ruby on rails - Error creating a new survey as the associated model(s) are invalid (questions) -


I have a survey as part of an application that I am creating can create user surveys and questions can dynamically specify (as they may want as many are), so I used the associated model with:

  # survey.rb has_many: survey_questions, dependant = & gt ; : Has_many is destroyed: survey_answers, dependent => : After deletion_transfer: save_survey_questions validates_associated: survey_questions def save_survey_questions survey_questions.each do | T | If t.should_destroy? T.destroy else t.save (false) end-end survey survey_question_attributes = (survey_question_attributes) survey_question_attributes.each do | Properties | If Properties [: ID]. Block? Survey_questions.build (Features) and survey_question = survey_questation.net {| E E.id == Characteristics [: id] .to_i} Survey_question.dates = attributes end-end end # survey_movies controller. RB Diff New @ Survey = Survey News (@ survey.switter_questions.empty?) @ Survey.survey_questions.build end Response_to do | Format | Format.html # new.html.erb end end def @ all = survey New (Params [: Survey]) response_to do | Format | If @ survey.save format.html {redirect_to (survey_path (: id = & gt; @survey))} and format.html {rendere: action = & gt; "New"} End & End # Survey_question. RB Class Survey Q & A & lt; ActiveRecord :: Base is_to: Survey attr_accessor: should_destroy def should_destroy? Should_destroy.to_i is == 1 end validates_presence_of: question ,: survey_id end  

The problem is that when I get an error on the questions:

@ Errors = { "survey_questions" => [ "invalid", "invalid is invalid", ""]}

link surveys to believe Srvekshn_aidi the Srve_kvestns

Any ideas how can I win over it?

If I do not create a survey with any questions, then add them after editing, then it works perfectly.

I'm sure you can help a lot, there you will find some examples of related items. it is not being filled Srvekshn_aidi is your problem (because Srve_vived), basically you should define some of its models:

 class survey  true ... and 

via survey Survey will handle assumptions.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -