【问题标题】:undefined local variable or method on link_to in railsrails中link_to上未定义的局部变量或方法
【发布时间】:2013-05-19 22:22:21
【问题描述】:

那是link_to

<%= link_to('Dashboard', dashboard_index) do %>
  <i class="icon-play"></i>
<% end %>

这就是对应的rake routes 条目。

dashboard_index GET    /dashboard/index(.:format)     dashboard#index

可能出了什么问题?有什么建议或想法吗?

提前致谢 最好的祝福 否认

【问题讨论】:

    标签: ruby-on-rails-3 ruby-on-rails-3.2 routes link-to


    【解决方案1】:

    应该是

    <%= link_to(dashboard_index_path) do %>
      Dashboard
      <i class="icon-play"></i>
    <% end %>
    

    【讨论】:

    • 对于rake routes 输出中的每个条目,创建两个方法:dashboard_index_path,即"/dashboard/index",还有dashboard_index_url,类似于"http://mydomain.com/dashboard/index"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    相关资源
    最近更新 更多