ActionView: options_from_collection_for_select in rails view

104 Views Asked by At

I have select view in my rails project and it works properly. I wanna add a future but I can't do it.

Here is my controller code:

def new_feedback
@campaigns = Campaign.all
render "new_feedback", layout: false if request.xhr?

end

Here is part of my view code:

<label>Campaign: (<span class="required-star">*</span>)</label><br>
<%= f.select "campaign_id", options_from_collection_for_select(@campaigns, :id, :name), {prompt: ''}, class: 'campaign-select feedback-campaign', required: true %><br>

The above code works without any problem. I wanna add something as which campaign as I selected. The code it should be below that:

<% if (I selected campaign) id==265) %>
       ...something here...
    <%end%>

What I should put instead of '(I selected campaign)' that? Could anyone help me, please.

1

There are 1 best solutions below

0
Fer On

If you are inside the form block:

f.object.campaign_id == 265

You have to think that this will be run once when the page is being rendered. If you want to dynamically do something based on the user interaction, then you have to use javascript.