Good morning, I'm working with ruby on Rails and I'm having a little difficulty. I have a value in a @n variable, and I have a collection_select that fetches all values from a collection. what I want to do is select the value that is in the @n variable immediately. the value that is in @n is "cats". I have: <%= f.collection_select :isolated_id, @isolateds, :id, :name, prompt: true %>
where @isolateds
is my collection that includes the name "cats".
When I go to see the code in html I have:
<select id="resist_isolated_id" name="resist[isolated_id]">
<option value="">Please select</option>
<option value="1">cenas</option>
...
<option value="22">cats</option>
</select>
I wanted to: <option value="22" selected="selected">cats</option>
and if in colection_select put :selected => 22
it does me this, the problem is that if it is any other name without being "cats", I will not know at the outset what is your " value ", so I wanted to directly pass the variable @n but when I do :selected => "@n"
, it does not give anything. Can someone help me?