# get loop values into controller from view

**URL:** <https://discuss.rubyonrails.org/t/get-loop-values-into-controller-from-view/64235>\
**Category:** rubyonrails-talk\
**Created:** [June 19, 2012, 10:06am UTC](https://discuss.rubyonrails.org/t/get-loop-values-into-controller-from-view/64235 "2012-06-19T10:06:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amruby](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amruby](https://discuss.rubyonrails.org/u/amruby)\
**Post date:** [June 19, 2012, 10:06am UTC](https://discuss.rubyonrails.org/t/get-loop-values-into-controller-from-view/64235/1 "2012-06-19T10:06:11Z")

</div>

\<%= form\_tag({:action =\> ‘getrate’, :controller =\> ‘users’},{:method =\> :post}) do %\>

**\<% @eachskill.each do |loc| %\>**

\<%= submit\_tag loc ,:type =\> “button”, :id =\> loc ,:disabled =\>“disabled”, :class =\> “btn span2” %\>

&nbsp;

\<%= select\_tag( loc, “12345”.html\_safe,:class =\> “span1”)%\>

  

**\<% end %\>**

\<%= submit\_tag “Rate”, :class =\> “btn” %\>

\<% end %\>

Here i need to get all the values from select\_tag, into the controller,

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 19, 2012, 3:04pm UTC](https://discuss.rubyonrails.org/t/get-loop-values-into-controller-from-view/64235/2 "2012-06-19T15:04:55Z")

</div>

amruby wrote in post #1065102:

> \<%= form\_tag({:action =\> 'getrate', :controller =\> 'users'},{:method =\> :post}) do %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br\>\<br\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\*\<% @eachskill.each do |loc| %\>\* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= submit\_tag loc ,:type =\> "button", :id =\> loc ,:disabled =\>"disabled", :class =\> "btn span2" %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= select\_tag( loc,

"\<option\>\</option\>\<option\>1\</option\>\<option\>2\</option\>\<option\>3\</option\>\<option\>4\</option\>\<option\>5\</option\>".html\_safe,:class

> =\> "span1")%\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\*\<% end %\>\* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= submit\_tag "Rate", :class =\> "btn" %\> \<% end %\>
> 
> Here i need to get all the values from select\_tag, into the controller,

You are thinking backwards. Data should not flow from view to controller. It's the controller's job to provide that data to the view. Not the other way around.

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= select\_tag( loc,

"\<option\>\</option\>\<option\>1\</option\>\<option\>2\</option\>\<option\>3\</option\>\<option\>4\</option\>\<option\>5\</option\>".html\_safe,:class

> =\> "span1")%\>

This list of options is data. Move this data out of the view. If this is simply a static list of options then you might simply put this into an instance variable in the controller. Then use the helpers provided by Rails to generate the HTML for the options list. Having to put that .html\_safe directly into the view should be a trigger that you're doing something wrong.

See collection\_select, options\_from\_collection\_for\_select or the other related helpers. There are enough of these helpers to cover just about any situation. I'm sure one of them will suit your needs.

In any case pushing data from view to controller is not the right solution.
