私はRailsCast197をフォローして、このネストされたモデル/フォームを試し、このコードに2時間以上頭を悩ませてきましたが、役に立ちませんでした。私は何を見落としていますか?
私は次のモデルを持っています:
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
私のWorkoutsControllerには、次のものがあります。
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
テストを実行してブラウザーでコントローラーを呼び出すと、次のエラーが発生します。
undefined method `performed_sets' for #<Class:0x7f6ef6fa6560>
助けてくれてありがとう-私のRoRnoobilityは私を驚かせなくなります!
編集:fflyer05:コレクションを反復処理するRailsCastと同じコードを使用し、performed_exercises [0]でperformed_setsをビルドしようとしましたが、機能しません。他のことをすると、初期化されていない定数PerformedExercise::PerformedSetエラーが発生します