I have a User model, and a Goal model. The Goal model has a name, and a type column, which has the following three records right now.
name | type
------------------------
Read Novels | Reading
Read Newspaper | Reading
Write Reviews | Writing
Now I want to provide each user, an interface to fill in the number of hours they spend on this activity every month (hours_per_month), and the number of different days they do it (days_per_month).
Ideally, I’d want to work with the data like
current_user = User.find(params[:id])
current_user.goals.each do |goal|
puts goal.name
puts goal.type
puts goal.hours_per_month
puts goal.days_per_month
end
How should I create this new table/model, that joins the Goals to User, and have access to the static Goal attributes, and the user filled values, like the code sample above?
You could create an
Activitymodel and give it a table definition like:activities:
Then add to:
You can use a generator to do most of the work iirc.