I am trying to get the following params into a Rails form.
{:routine=>{
:name=>"Test"},
:arbitrary=>[
{:lift=>{
:exercise_id=>"1",
:infos=>[
{:weight=>"250", :repetiton=>"8"},
{:weight=>"275", :repetition=>"6"}
]
}
},
{:lift=>{
:exercise_id=>"2",
:infos=>[
{:weight=>"405", :repetition=>"12"},
{:weight=>"445", :repetition=>"4"}
]
}
}
]
}
In learned how to properly set a form in rails I have realized that deciding what I would like my params to be before I begin constructing the form is very helpful. I am running into a problem at an early stage in my form.
In the above params, we have an routine which has a name. That routine has many lifts, which is a joins between the routine and the exercise. In a select field, I am attempting to have a user pick an exercise from the Exercise.all and set the instance of exercise as the exercise_id so that along with a routine_id, a lift can be created. Each lift is going to have many sets (infos in the params shown above, rails would not let me use set), which have weight an repetitions.
In the short form that I currently have, the last exercise that I choose is the only exercise being passed in the params. I am guessing because when mass assigning, the first :lift gets overridden by the second :lift and so on. Here is the form I currently have
<%= form_tag routines_path %>
<%= label_tag "routine[name]", "Routine Name" %>
<%= text_field_tag "routine[name]" %><br />
<%= select("arbitrary[][lift]", "exercise_id", Exercise.all.collect {|p| [ p.name, p.id] }) %><br />
<%= select("arbitrary[][lift]", "exercise_id", Exercise.all.collect {|p| [ p.name, p.id] }) %>
<%= submit_tag "Submit Routine" %>
Is there a way I can accomplish these params or am I going for the wrong params in general. I am guessing that if each :lift was called something different that would work but not what I am trying to do. Thank you to anyone that can help.