iTake
iTake

Reputation: 315

retrieving the ID from a selected drop down list box in ruby on rails

So I have this:

<%= select("selected_red1_robot", "id", @robots.map { |u| [u.team_number,u.id]}) %>

when I do in my controller I see this:

params['selected_red1_robot']

and I see this in my return:

"selected_red1_robot"=>{"id"=>"2"}

I want to do something like:

@roboMatch.robot_id = params['selected_red1_robot']

What am I missing here?

Upvotes: 1

Views: 549

Answers (1)

Marty Cortez
Marty Cortez

Reputation: 2343

You're close to the id, you just need to reference it as follows:

@roboMatch.robot_id = params['selected_red1_robot']['id']

Upvotes: 1

Related Questions