【发布时间】:2011-07-14 06:38:59
【问题描述】:
由于某种原因,特定控制器的常规路径名不起作用? (轨道 3.1)
我使用 ryan bates 漂亮的脚手架创建了一个控制器。只是一个控制器,没有底层模型。
在我拥有的控制器中
class ProjectTemplatesController < ApplicationController
# a bunch of stuff
def new
@project = Project.new
end
#more stuff
end
在我看来 (app/views/project_templates/index.html.erb) 我有:
<p><%= link_to "New Project Templates", new_project_templates_path %></p>
但是我得到了错误
undefined local variable or method `new_project_templates_path' for #<#<Class:0x2ab9c24>:0x2ab80e0>
在我的 routes.rb 文件中,我将控制器声明为与其他所有控制器一样的资源
resources :project_templates
如果我更改要使用的链接
<%= link_to "New Project Templates", {:controller=>"project_templates, :action=>"new"} %>
那么它就完美了?!为什么action_controller_path的命名约定在这种情况下不起作用?
【问题讨论】:
-
new_project_template_path 有效吗?如果是这样,那将是由于屈折库
-
您是否已经运行
rake routes,以检查该路线是否如您所想的那样存在?
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1