lundi 23 mars 2015

Rails form select to return all params in an object

I have an list in my controller that looks like:



@relatives = [
{
id: '1',
firstName: 'John',
lastName: 'Smith',
related: 'Father'
},
{
id: '2',
firstName: 'Sarah',
lastName: 'Smith',
related: 'Mother'
}
]


I would like to put this list in a form select in my view. So it would be a drop-down of relatives, but it would only display the firstName field in the select. When the user selects an object and submits the form, the entire relative object would get passed to the controller in the params.


I was looking at the rails collection_select API, but couldn't figure out how to select an entire object in the form.


Aucun commentaire:

Enregistrer un commentaire