【问题标题】:Rails url_for not finding the route which appears in Rake Routes?Rails url_for 找不到出现在 Rake Routes 中的路由?
【发布时间】:2010-12-02 02:52:09
【问题描述】:

我有以下 rake 路线:

user GET    /users/:id(.:format)                                     {:action=>"show", :controller=>"users"}

但是当我这样做时,对于电子邮件模板:

<%= link_to(@comment.user.full_name, user_url(:only_path => false), :style => 'color:#5196E3;text-decoration:underline;') %>

我收到以下错误:“ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users"}):"

想法?谢谢

【问题讨论】:

  • :style =&gt; 'color:#5196E3;text-decoration:underline;' - 我认为最好把它放在你的 CSS 中。

标签: ruby-on-rails


【解决方案1】:

如果您查看路由,它需要一个 :id 来解析。所以你应该像这样向用户提供:

user_url(@comment.user, :only_path => false)

【讨论】:

    【解决方案2】:

    这有时令人困惑。请注意,在您的 rake 输出中,路由引擎需要一个 id。如果它没有得到一个,它就无法识别路线。以下是您在控制器/视图中的操作方式:

    user_url(@comment.user)
    

    user_url(@comment.user.id)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多