ruby on rails - Model with unknown number of an attribute -
Ruby on Rail 4
I want to make a model "test" which is anywhere from 2 There will be several tests for 200 questions each test questions will have different forms.
I was thinking of making an attribute called "Question_s". I have to do a string which is a delimited question_a
Or I can make the model with 200 question_ID properties. This will simplify and fasten the question_id (s).
Is there any other way? Who likes? What if I have 1,000 questions?
model / test_question.rb
class test question & lt; ActiveRecord :: Base is_to: question is_to: test end model / question.rb
class question & lt; ActiveRecord :: Base has_many: test termination db / migrate / initial_migration.rb
class initial migration & lt; ActiveRecord :: Migration DF self.up create_table: test do | T | T.string: name end create_table: test_questions do | T | T.references: Table t.references: question end create_table: questions do | T | T.string: name end end This will also make appropriate indexes.
Comments
Post a Comment