How to enable "Please select ..." (default / prompt) in the grouped drop-down list?

The code I'm using for the dropdown is this:

<%= f.select :post_type_id, option_groups_from_collection_for_select(@categories, :post_types, :name, :id, :name) %>

It neatly divides the parameters into opt groups.

But how do I change the code to include a prompt (or default value) in "Please select ..."?

It seems hard to group dropdowns. (The rails seem to suggest using a hash, but I tried several alternatives without success.)

+5
source share
1 answer

Bah, right after I posted the question, I found the answer in the docs for select, and not in the option_groups_from_collection_for_selectdocs where I looked.

Answer:

<%= f.select :post_type_id, option_groups_from_collection_for_select(@categories, :post_types, :name, :id, :name), :include_blank => "Please select..." %>
+7
source

All Articles