views:

53

answers:

1

Hi,

I have 2 models, Assessments and Questions. Assessments have many questions.

In routes, I have:

map.resources :assessments, :has_many => :questions
map.root :assessments

I checked rake routes, it's as expected

On the form to create a new question, I get the following error:

undefined method `questions_path' for #<ActionView::Base:0x6d3cdb8>

If I take out the form, the view loads fine, so I think it's something with the code in this view - I'm getting the error on the form_for line:

<h1>New question</h1>

<% form_for [@assessment, @question] do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :content %><br />
    <%= f.text_field :content %>
  </p>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

<%= link_to 'Cancel', assessment_path(@assessment) %>

Rake Routes - http://pastebin.com/6fKUPTjq

Code to question controller - http://pastebin.com/URzpmEcg

Code to assessment controller - http://pastebin.com/HstvFTq4

Can anyone help me debug it? Thanks!

+1  A: 

You need to have

@assessment = Assessment.find(params[:assessment_id])

in the controller. Otherwise, @assessment is nil.

mathepic
Thanks for all the help, and patience :)
stringo0