Ruby on Rails 4 - structuring database with nested attributes -


i'm having considerable trouble setting database using nested attributes, , after many hours of googling can't find answer. should keep trying fix this, or start on because idea how structure database somehow wrong?

my structure is:

questions (questions asked in wizard, presented depending on answers previous questions)

responses (possible answers questions, user_input save user's input response (e.g. particular number) in connection particular experiment)

experiment (the thing wizard assembling)

user (has multiple experiments, each separate run of wizard)

example seed:

    question.create(  {   :title => 'rm power analysis 2',   :content => 'look next step should be. maybe display result of power analysis.',    :responses_attributes => [     { content: 'seperate measurements per subject:', input_type: 'number 2 20', next_question: 'rm power analysis 2'},      { content: 'seperate measurements per subject:', input_type: 'number 2 20', next_question: 'rm power analysis 2'},     { content: 'unsure', input_type: 'radio', next_question: 'rm power analysis 2' }   ],    :tell_me_more => 'lengthy explanation text goes here.'  } )   class createquestions < activerecord::migration   def change     create_table :questions |t|       t.string :title       t.text :content       t.has_many :responses       t.has_many :experiments, through: :responses       t.timestamps     end   end end  class addtellmemoretoquestions < activerecord::migration   def change     add_column :questions, :tell_me_more, :text   end end  class question < activerecord::base    # ownerships   has_many :responses, :dependent => :destroy   accepts_nested_attributes_for :responses  end 

other classes

class experiment < activerecord::base #ownerships has_many :responses accepts_nested_attributes_for :responses, :reject_if => lambda { |a|   a[:content].blank? } has_many :questions, :through => :responses belongs_to :user    def current_question     @current_question || questions.first   end  end  class response < activerecord::base    # ownerships   belongs_to :question   belongs_to :experiment end  class user < activerecord::base    # ownerships   has_many :experiments, :dependent => :destroy   accepts_nested_attributes_for :experiments, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true   has_many :responses, :through => :experiments   accepts_nested_attributes_for :responses, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true   ... end 

attempt @ uml structure


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -