\'users#profile\', :as => :profile" />
开发者

Routing error on Rails 3

I'm working on a profile page, so the config is like this:

routes.rb
=> match "user/:login(*path)" => 'users#profile', :as => :profile
rake routes
=> profile    /user/:login(*path)(.:format)    {:action=>"profile", :controller=>"users"}
on console
> Rails.application.routes.recognize_path("/user/example/whatever")
=> {:action=>"profile", :login=>"example", :controller=>"users", :path=>"/whatever"}

And I have a profile action in UsersControllers. But when I use

<%= link_to user.name, profile_path(user.login) %>

in a view I get the error

No route matches {:login=>"example", :controller=>"users", :act开发者_Go百科ion=>"profile"}

What am I missing? Thanks

Update:

Thanks for the answer and attention, Steve!

After a lot of time trying, a coworker find what I was missing: the problem was only with some logins that are emails too, with "@", ".", etc. The solution was adding to_url at params[:login] in link_to:

<%= link_to 'name', profile_path(params[:login].to_url) %>

Again, thanks for the attention!


Using your configuration, the route and helper seem to work fine in a Rails 3.0.5 sample app.

I verified the route helper profile_path in the Rails console:

>> app.profile_path('example')
=> "/user/example"

and checked that it worked in the view as well:

<%= link_to 'name', profile_path(params[:login]) %>

No route errors in either place. And putting <%= debug(params) %> in the view shows the path '/user/example/whatever' is being parsed correctly:

--- !map:ActiveSupport::HashWithIndifferentAccess 
controller: users
action: profile
login: example
path: /whatever
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜