ruby on rails - Link in Nested Forms returning Invalid Association -
i'm using nested forms create complex list of forms group of models associated it. however, when add link_to_add link in form returns error message,
invalid association. make sure accepts_nested_attributes_for used :workout_exercises association.
if remove link works fine. have assume it's view error since removing causes no issues , imagine bring issue if associations or accepted nested forms wasn't working. what's wrong code , how fix it.
= nested_form_for(@client_workout) |f| = f.number_field :client_id, placeholder: "client's name" = f.text_field :description, placeholder: "description" = f.text_field :note, placeholder: "notes" = f.fields_for :workouts |workout_form| = workout_form.text_field :name, placeholder: "workout name" = workout_form.fields_for :workout_exercises |exercise_details_form| div create exercise = exercise_details_form.fields_for :exercise |exercise_form| = exercise_form.text_field :name, placeholder: "exercise name" = exercise_details_form.text_field :reps, placeholder: "reps" = exercise_details_form.text_field :sets, placeholder: "sets" = exercise_details_form.text_field :weight, placeholder: "weight" = exercise_details_form.text_field :category, placeholder: "category" = exercise_details_form.link_to_remove "remove exercise", class: "btn btn-danger" / line of code below causing problem = workout_form.link_to_add "add exercise", :workout_exercises = f.submit class: "btn btn-success"
my client_workout
model
class clientworkout < activerecord::base attr_accessible :workout_id, :description, :note belongs_to :workout accepts_nested_attributes_for :workout end
you should invert because workout
has many workout_clients
= nested_form_for(@workout) |f|
and
= f.fields_for :client_workouts |clientworkout_form|
Comments
Post a Comment