Reputation: 17
I'm trying to put default option of @languages - 'All Languages' Here is view:
.dropdown-search-filter
= select_tag "languages", options_from_collection_for_select(@languages, "id", "to_label", selected: params[:languages]), prompt: "All Languages"
.dropdown-search-filter.search-select-tag
= select_tag "destination", content_tag(:option,'All Destinations',:value=>"all")+options_from_collection_for_select(@destinations, "id", "name", selected: params[:destination])
It still puts English as a default: here screenshot.
What am I doing wrong?
Upvotes: 0
Views: 2766
Reputation: 370
You are trying to access params in view which you can not. Make an instance variable like @language_id and use it in the view
Upvotes: 1
Reputation: 342
As I can read in the documentation (link), something like:
select_tag "languages", options_from_collection_for_select(@languages, "id", "to_label", params[:languages]), prompt: "All Languages"
Note that params[:languages]
must be a valid id of your languages collection, because the fourth parameter (default selection) is based on the id's of the options (the field named in the second parameter).
Does this work for you?
Upvotes: 0