RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: dedgars
my mistake was that I did not add 'survey_id:integer' while generating questions model. it solved the problem
no :(
Hi! Please help! I am stuck on this error:
ActiveRecord::UnknownAttributeError in SurveysController#new unknown attribute: survey_id
Rails 3.2.2
class Survey < ActiveRecord::Base has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true end
class Question < ActiveRecord::Base belongs_to :survey has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true end
class Answer < ActiveRecord::Base belongs_to :question end ```surveys_controller.rb ... def new @survey = Survey.new 3.times do question = @survey.questions.build 4.times { question.answers.build } end end ...
<%= form_for @survey do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <%= f.fields_for :questions do |builder| %> <%= render "question_fields", :f => builder %> <% end %> <p><%= f.submit "Submit" %></p> <% end %>
my mistake was that I did not add 'survey_id:integer' while generating questions model. it solved the problem
no :(
Hi! Please help!
I am stuck on this error:
ActiveRecord::UnknownAttributeError in SurveysController#new
unknown attribute: survey_id
Rails 3.2.2