简体   繁体   English

Rails 3命名路线

[英]rails 3 named routes

I am upgrading my application to rails 3. My old route was 我正在将应用程序升级到Rails3。我以前的路线是

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

I changed this to: 我将其更改为:

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

This works when I enter in the route say /profile/red99 当我输入说/ 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"} 我给我一个错误:没有路由匹配{:controller =>“ profile”,:action =>“ red99”}

If you want to specify the URL for the profile you still need to use the parameters: 如果要为概要文件指定URL,则仍然需要使用参数:

: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. 您没有通过定义该路由来更改action参数,只是通过隐式指定action来使URL更具可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM