= f.select:from_id, decorated_froms.map { |from| [from.name, from.id] }, include_blank: "Please select a role to send a message."
include_blank
<%= f.select :from_id, decorated_froms.map { |from| [from.name, from.id] }, include_blank: 'Please select a role to send a message.') %>
This will always include a blank option in the select, which will allow people to set the value back to the blank value if they're seeing this on an edit form.
prompt
which is the better option
<%= f.select :from_id, decorated_froms.map { |from| [from.name, from.id] }, prompt: 'Please select a role to send a message.') %>
This will include the specified prompt value, so long as the field hasn't already been set. If it has (on an edit form for example), there's no need to remind the user that they need to select a value so the prompt doesn't appear.
More on #select
https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.