开发者

rails 3 named routes

开发者 https://www.devze.com 2023-01-14 21:02 出处:网络
I am upgrading my application to rails 3.My old route was map.profile \'profile/:login\', :controller => \'profile\', :action => \'show\'

I am upgrading my application to rails 3. My old route was

map.profile 'profile/:login', :controller => 'profile', :action => 'show'

I changed this to:

 match 'profile/:login', :to => 'profile#show'

This works 开发者_如何学Pythonwhen I enter in the route say /profile/red99

But when I use a generic link like:

 <%= link_to image.user.login, :controller => "profile", :action => image.user.login %>  

or

 <%= link_to "public profile", :controller => "profile", :action => current_user.login %>

I gives me the error No route matches {:controller=>"profile", :action=>"red99"}


If you want to specify the URL for the profile you still need to use the parameters:

:controller => 'profile', :action => 'show', :login => current_user.login

You haven't changed the action parameter by defining that route, you've simply made a more readable URL by implicitly specifying the action.

0

精彩评论

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