0

I have a week model (has_many days) and days model (belongs_to week), initially I generate a form that has 7 days.

Each day has some inputs (class name and description), I want to add a feature where user can add more lass name and descriptions dynamically. Do I need to create another model to hold these attributes or there is another way to handle that?

I was thinking about using cocoon and just add days dynamically. Any recommendations? I use rails 4 and ruby 2.

1

1 Answer 1

1

If you want each day to be able to have multiple descriptions and multiple class names then the easiest way is to have a model for description and a model for class name:

class Week < ActiveRecord::Base
  has_many :days
end

class Day < ActiveRecord::Base
  belongs_to :week
  has_many :descriptions
  has_many :class_names
end

class Description < ActiveRecord::Base
  belongs_to :day
end

class ClassName < ActiveRecord::Base
  belongs_to :day
end
Sign up to request clarification or add additional context in comments.

3 Comments

how do I group them? So if I add new description, I add new class name as well?
you could have the description be a property of the class name or have the class name be a property of the description. It might be best at this point to do some thinking about your db schema. Have you done anything with relational databases before?
Yes, I have, not on this scale though. It will be a good practice. Thanks for your suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.