Reputation: 1097
I'm sure there is a very simple answer to this, but I'm struggling to figure it out. Timesheet has_many Runs, and a Run belongs_to a Timesheet. On my Timesheet#show page I'd like to have a select box that is populated only with @timesheet.runs. Is it possible to have a user select an option from the select box, which then updates an instance variable in the TimesheetController?
Upvotes: 0
Views: 252
Reputation: 33954
Sure, the values from the form just come across as a hash. You can access its values and assign them to any variable, like any other hash. The only thing special about the params
hash is that it's automatically generated from your form, which is convenient.
So, if you have a form with a select with an id of "runs", then in your controller, if you want to assign the value of that select to a variable called run_value
:
def update
run_value = params[:runs]
end
Or, your form might also have an id
of, say, timesheet
, in which case your controller would look something like:
def update
run_value = params[:timesheet][:runs]
end
Upvotes: 1