I have a rails app with the following:
class Habit < ActiveRecord::Base
has_many :habit_journals
has_many :road_blocks
class RoadBlock < ActiveRecord::Base
belongs_to :habit
has_many :road_block_histories
class HabitJournal < ActiveRecord::Base
belongs_to :habit
end
I have a form that creates HabitJournals, although within this form I am trying to create RoadBlockHistories (which is just a rating on a RoadBlock over time)
I can't seem to work out how to create the form for this.
Habits have many HabitJournals and RoadBlocks. RoadBlockHistories don't relate directly to HabitJournals, but I would still like to capture these at the same form submission.
Any help would be appreciated.
Cheers M
Sorry, I realised I need to add additional info. This is Rails 4.1
A user will create a habit such as 'Be healthier'. They then will create a number of road blocks to this habit such as 'Eating chocolate at night' and 'sleeping in instead of exercising'.
When the user views a habit they can add a journal entry (an update of how they are doing establishing the habit).
When adding a journal entry I'd like the user to be displayed with all their "road blocks" with a dropdown to select a rating (which is a mark out of 10 of how they are going with that road block). This rating would create a road_block_history object.
Hopefully this clarifies.
Cheers M
Rails versionyou are using?accepts_nested_attributesformwithhabit,then you can easilynesttheroad_block_histories.