ruby on rails - simple_form association not working as expected -
i have simple_form building form responseset. response set collection of responses questionnaire (which has_many questions). question can have many answers. (it's complicated, know). when attempting render out radio buttons answers particular question, none of radio buttons selected though there answers related response. changing as: :check_boxes seems work correctly. bug w/ simpleform?
= simple_form_for @response_set |rs|   = rs.simple_fields_for :responses |r|     - if r.object.question.class <= question::singlechoice       = r.association :answers, as: :radio_buttons, collection: r.object.question.answers, label_method: :text, label: false response_set.rb
class responseset < activerecord::base   has_many :responses   accepts_nested_attributes_for :responses end response.rb
class response < activerecord::base   belongs_to :question   has_and_belongs_to_many :answers   belongs_to :response_set   has_many :questions,     through: :answers   accepts_nested_attributes_for :answers end questionnaire.rb
class questionnaire < activerecord::base   has_many :response_sets end answer.rb
class answer < activerecord::base   has_many :responses   belongs_to :question end question.rb
class question < activerecord::base   has_many :responses,     through: :answers   has_many :answers end 
try adding :selected option association. example:
= r.association :answers,    as: :radio_buttons,    collection: r.object.question.answers,    label_method: :text,    label: false,    selected: r.object.question.answers.select {|ans| ans.responses.any? } also, if need build lot of questionnaires/surveys (especially if they're complicated), i'm huge fan of surveyor gem, though default css ugly.
Comments
Post a Comment