form_for - 访问视图中的控制器变量时出错(rails 3)

时间:2011-08-11 23:28:25

标签: ruby-on-rails-3 form-for

我有一个非常简单的模型/视图但由于某种原因我似乎无法访问新的记录变量,因此得到错误:

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"

1 个答案:

答案 0 :(得分:1)

您没有表单中的帖子路径。

也许放

resources :checklists

取代

#checklists
get "checklists/new"
get "checklists/edit"
...