Paul Phoenix
Paul Phoenix

Reputation: 1433

rails select or drop down, display value vs original value

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

Answers (1)

zwippie
zwippie

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

Related Questions