开发者

form_for - error accessing a controller variable in the view (rails 3)

开发者 https://www.devze.com 2023-03-27 07:11 出处:网络
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:

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 h开发者_StackOverflowit 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"


You don't have a path for the post from the form.

Maybe put

resources :checklists

in place of

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

精彩评论

暂无评论...
验证码 换一张
取 消