Reputation: 2144
I have an array like this:
@array = [[1, a], [2, b], [3, c] ............]
i want to create a drop down in my view with an
f.select
the drop down should have only the numbers i.e., [1, 2, 3, ....]
How can i create a drop down with only the numbers and an f.select
in my view?
Upvotes: 0
Views: 2158
Reputation: 64
Just use. It is very easy to implement.
select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...])
or
f.select(:city_id, [['Lisbon', 1], ['Madrid', 2], ...])
Notice that the third parameter, the options array, is the same kind of argument you pass to options_for_select. One advantage here is that you don’t have to worry about pre-selecting the correct city if the user already has one — Rails will do this for you by reading from the @person.city_id attribute.
Upvotes: 0