Reputation: 1433
Is it possible in rails to show some value in the drop down which is when selected or retrieved we can get some other value.
Say for example I have one drop down which has values : BMW Audi Merc
On selection of BMW, when the form is submitted I want to send the value as 'B' , also when i Use jquery to check the selected value I want it to return 'B'
Upvotes: 1
Views: 990
Reputation: 15515
Are you looking for another way to provide options to a dropdown in Rails?
Instead of creating options for the dropdown with:
options_for_select(['BMW', 'Audi', 'Merc'])
Pass in the options like:
options_for_select([['BMW', 'B'], ['Audi', 'A'], ['Merc', 'M']])
The first value of each pair is the label that is shown, the second value is the key that will be used in the serialization of the form (posting the form to the server).
Upvotes: 1