user786610
user786610

Reputation:

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

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"

Upvotes: 1

Views: 216

Answers (1)

Douglas Lovell
Douglas Lovell

Reputation: 1607

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"
...

Upvotes: 1

Related Questions