I have a collection_select
as below. What I want is to display the prompt
value on page load and not the id
of the object. But now it displays the value of the id
of the f
object of the form on page load.
How can I change it so that as soon as the page loads the prompt
value is displayed and the other id
values are shown when the collection_select
is clicked?
<%= f.collection_select(:id, Animal.all, :id, :id, {include_blank: 'Select animal'}, selected: params[:id]) %>
I tried this also:
<%= f.collection_select(:id, Animal.all, :id, :id, {include_blank: 'Select animal'}, selected: params[:id]) %>
This time Select animal
is shown at the top when collection_select
is clicked but the id
of the present Animal
object is displayed on page load. In the first case prompt
value is not displayed anywhere. How can I change it?
您可以尝试跟随它,
<%= f.collection_select(:id, Animal.all, :id, :id, include_blank: 'Select animal', selected: Animal.find(params[:id])) %>
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.