Sumeet Masih
Sumeet Masih

Reputation: 607

How to add placeholder kinda thing in ruby select

1) Is there any way I can add a placeholder/first option as "(Select City)"

<%= f.select :city_id, options_for_select(@cities.collect { |city|
    [city.name.titleize, city.id] }, 1), {}, { id: 'cities_select'} %>

2) Can I use collection_select or say please if anyone can transform it into a collection_select tag (with @cities array not City model)

Upvotes: 1

Views: 1816

Answers (1)

jeremywoertink
jeremywoertink

Reputation: 2341

You can use the prompt or include_blank: 'My Placeholder options in the select method http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag

f.select :city_id, options_for_select(@cities.collect { |city|
[city.name.titleize, city.id] }, 1), {include_blank: 'Select Something'}, { id: 'cities_select'}

Upvotes: 3

Related Questions