【发布时间】:2010-10-15 23:27:26
【问题描述】:
我正在编写一个带有一个主控制器的简单 Rails 应用程序,我想将 /(:action(:id)) 映射到这个控制器(基本上删除开头的控制器前缀),但仍然有我通过使用 map.resources 获得的路径助手.
我尝试了map.root :controller => 'notes',但出现错误:
#<:base:0x102038b50> 的未定义方法 `note_path'
我在哪里使用link_to_unless_current 函数。
编辑:这是 index.html.erb 中给出错误的代码。
<% for note in category.notes %>
<h3><%= link_to_unless_current h(numbered_title note), note %></h3>
<% end %>
【问题讨论】:
-
需要更多信息。就像使用 link_to_unless_current 在页面中发布实际代码一样,当你去那里时,去根工作吗?另外我认为您需要一个默认操作,我认为您不能说只是映射到控制器;它怎么知道要画什么?
-
map.root :controller => 'notes', :action => 'index'也不起作用。 -
此外,我不仅想映射
/,还想映射/:id、/:id/edit等。 -
好吧,#note_path 将被定义,如果你有一个命名的笔记路由......你的 route.rb 文件中真的有 map.resources :notes 吗?你能告诉我们你的完整 routes.rb 吗?
-
我刚刚意识到您正在使用
map,这是定义路由的旧方法。你在 Rails 2.3 上吗?
标签: ruby-on-rails routing