【问题标题】:rails 3 named routesrails 3 命名路线
【发布时间】:2010-09-02 22:59:12
【问题描述】:

我正在将我的应用程序升级到 rails 3。我的旧路线是

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

我把它改成了:

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

当我输入路线说 /profile/red99 时,这有效

但是当我使用通用链接时:

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

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

我给了我错误 No route matches {:controller=>"profile", :action=>"red99"}

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 routing routes


    【解决方案1】:

    如果你想为配置文件指定 URL,你仍然需要使用参数:

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

    您并没有通过定义该路由来更改action 参数,您只是通过隐式指定操作创建了一个更具可读性的 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多