I've been following RailsCast 197 to try this nested models/forms and have cracked my head over this code for over 2 hours, but to no avail. What am I overlooking?
I have the following Models:
class Workout < ActiveRecord::Base
belongs_to :user
has_many :performed_exercises, :dependent => :destroy
accepts_nested_attributes_for :performed_exercises
end
class PerformedExercise < ActiveRecord::Base
belongs_to :workout
belongs_to :exercise
has_many :performed_sets, :dependent => :destroy
accepts_nested_attributes_for :performed_sets
end
class PerformedSet < ActiveRecord::Base
belongs_to :performed_exercise
end
In my WorkoutsController I have the following:
def new
# We only need to build one of each since they will be added dynamically
@workout = Workout.new
@workout.performed_exercises.build
@workout.performed_exercises.performed_sets.build
end
When I run the test and invoke the controller in the browser, I get the following error:
undefined method `performed_sets' for #<Class:0x7f6ef6fa6560>
Thanks in advance for any help - my RoR noobility ceases to amaze me!
Edit: fflyer05: I tried using the same code as the RailsCast with the iterating over the collection, as well as attempting to build the performed_sets on performed_exercises[0] - but it doesn't work. Doing anything else, I get an uninitialized constant PerformedExercise::PerformedSet error