Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Pass select_tag selections from view back to controller

select_tag selections controller view

  • Please log in to reply
1 reply to this topic

#1 RensterUK

RensterUK

    Passenger

  • Members
  • 7 posts

Posted 19 March 2014 - 10:47 AM

I have a multi select list:
 
        <%= select_tag "selectedSuites", options_for_select(@suitesInPerforce), {:multiple => true, :class => "chzn-select", :style => "width:100%;", :style => "height:100%"} %>
I now want to add a button to the same view, which will pass the list of selected options in my listbox back to a controller function, for some server side processing:
  <button id='SyncButton' onclick="<%= controller.dostuff(selectedSuites_tag_selections)%>">Sync</button>

 

How do I "grab" the list of selected options to pass into a function? Also, please bear in mind another post of mine - https://railsforum.c...r-1-or-1-for-0/ - so even when I have the list, I seem to be hitting problems on controller side methods.

 

Help please?! :)



#2 RensterUK

RensterUK

    Passenger

  • Members
  • 7 posts

Posted 21 March 2014 - 08:56 AM   Best Answer

Solved! I just needed to learn a bit more about Rails :)

 

So doing things as per the above is WRONG!

 

A form (a bit like the following), together with appropriate POST route entry was what I needed!
 

<%= form_tag 'synchronise', :controller=>'perforce_sync', :action=>'synchronise', :method=>'post' do %>
    <%= select_tag "perforceSuites", options_for_select(@suitesInPerforce), {:multiple => true} %>
    <%= select_tag "localSuites", options_for_select(@suitesLocally), {:multiple => true, :disabled => true} %>
   <br>
    <div  style="width:100%;text-align:center">
    <%= submit_tag 'SYNCHRONISE' %>
    </div>
<% end %>






Also tagged with one or more of these keywords: select_tag, selections, controller, view

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users