form_for - 访问视图中的控制器变量时出错 (rails 3)
我有一个非常简单的模型/视图,但由于某种原因,我似乎无法访问新的记录变量,因此出现错误:
undefined method `hash_for_checklists_path' for # Module:<0x00000100f8b9b0>
我已经在这个问题上头撞墙几个小时了。谁能看到我做错了什么吗?
控制器
class ChecklistsController < ApplicationController
def new
@title = "New Checklist"
@checklist = Checklist.new
end
[...]
end
(顺便说一句,我的 application.html.erb 文件获取 @title 变量没有问题。)
视图(new.html.erb)
<%= form_for @checklist do |f| -%>
Routes.rb
devise_for :users
resources :checklist_item_categories, :as => 'item_categories' do
resources :checklist_items
end
resources :checklist_categories do
resources :checklists
end
match 'checklists/new', :to => 'checklists#new'
#pages
get "pages/home"
get "pages/contact"
#checklist items
get "checklist_items/new"
#checklists
get "checklists/new"
get "checklists/edit"
get "checklists/show"
get "checklists/index"
#categories
get "abstract_categories/new"
I have a very simple model/view but for some reason I can't seem to access the new record variable and therefore get the error:
undefined method `hash_for_checklists_path' for # Module:<0x00000100f8b9b0>
I've hit my head against a wall on this for several hours. Can anyone see what I'm doing wrong?
Controller
class ChecklistsController < ApplicationController
def new
@title = "New Checklist"
@checklist = Checklist.new
end
[...]
end
(incidentally my application.html.erb file has no problem getting the @title variable.)
View (new.html.erb)
<%= form_for @checklist do |f| -%>
Routes.rb
devise_for :users
resources :checklist_item_categories, :as => 'item_categories' do
resources :checklist_items
end
resources :checklist_categories do
resources :checklists
end
match 'checklists/new', :to => 'checklists#new'
#pages
get "pages/home"
get "pages/contact"
#checklist items
get "checklist_items/new"
#checklists
get "checklists/new"
get "checklists/edit"
get "checklists/show"
get "checklists/index"
#categories
get "abstract_categories/new"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有表单中帖子的路径。
也许可以
代替
You don't have a path for the post from the form.
Maybe put
in place of