include_blank will always create an option tag, prompt will only create an option tag when creating a new record - in most cases I prefer include_blank
both take either a boolean or a string, if true is passed then include_blank will create an option with no display text and prompt defaults to the display text of 'Please Select'
collection_select(:product,
:category_id,
Category.all,
:id,
:title,
{:prompt => true}
)
collection_select(:product,
:category_id,
Category.all,
:id,
:title,
{:include_blank => 'Please Select'}
)
both of these result in the same html, but the first one will not include the 'Please Select' option when you return to edit the previously created Product
See also
5 comments:
Thanks - I was wondering what the difference was...
Thank you!! I was scratching my head to find how i could force "prompt" message in collection_select!
Thank you! I was trying to figure out why I couldn't get the prompt to show up, now I know why. I was editing an existing record.
Thank you!
that helped, thx!
Post a Comment