Monday, 15 September 2014

ruby on rails - belongs_to id not being set activeadmin -



ruby on rails - belongs_to id not being set activeadmin -

i have 2 models: asssessment , question organized this:

class question < activerecord::base belongs_to :assessment class assessment < activerecord::base has_many :questions

i'm trying create activeadmin (ver 1.0.0) interface create assessments , add together questions them. far i've tried making questions tab:

activeadmin.register question permit_params :question_text, :question_type, :scale_min, :scale_max form |f| f.inputs "question information" f.input :assessment, :as => :select, :collection => assessment.non_daily_assessments f.input :question_type, :as => :select, :collection => question.human_readable_question_types.keys f.input :question_text, :input_html => {:rows => 2, :cols => 10} f.input :scale_min f.input :scale_max end f.actions end

non_daily_assessments returns subset of assessments able select list of assessments, when save question , taken "view question" page question's assessment_id empty.

similarly, if create assessments tab:

activeadmin.register assessment permit_params :name, :questions form |f| f.inputs "assessment information" f.input :name, :input_html => {:rows => 1, :cols => 10} f.has_many :questions, :allow_destroy => true, :heading => 'questions' |qf| qf.input :question_type, :as => :select, :collection => question.human_readable_question_types.keys qf.input :question_text, :input_html => {:rows => 2, :cols => 10} qf.input :scale_min qf.input :scale_max end end f.actions end

i able go particular assessment , start adding questions, when reload page they're gone. going console see questions created, assessment_id's nil through question tab.

what right way create activeadmin interface belongs_to has_many relationship?

let me know if need more information.

your permit_params incomplete. have @ answer: nested form in activeadmin not saving updates

you need add together :assessment_id permit_params in question section, , if want able edit questions assessments, you're missing accepts_nested_attributes_for :questions in assessment model, , you'll need alter permit_params in assessment section

permit_params :name, questions_attributes: [:id, :question_type, :question_text, :scale_min, :scale_max]

ruby-on-rails activerecord activeadmin

No comments:

Post a Comment