# select\_tag values from model?

**URL:** <https://discuss.rubyonrails.org/t/select-tag-values-from-model/5310>\
**Category:** rubyonrails-talk\
**Created:** [December 1, 2006, 6:31am UTC](https://discuss.rubyonrails.org/t/select-tag-values-from-model/5310 "2006-12-01T06:31:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajkumar\_S](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@Rajkumar\_S](https://discuss.rubyonrails.org/u/Rajkumar_S)\
**Post date:** [December 1, 2006, 6:31am UTC](https://discuss.rubyonrails.org/t/select-tag-values-from-model/5310/1 "2006-12-01T06:31:36Z")

</div>

Hello,

I have a form [using start\_form\_tag] with a select\_tag. I need to populate the values [id and name] from a model. So far all the examples for populating values of select box from database uses form\_for and form.collection\_select method.

Is there a similar way to do that for from\_tag and select\_tag?

I am happy atleast if I get a method to pass a name and id to the select\_tag, so that the display is name and id is posted.

regards,

raj

---

<div class="post-metadata">

**Author:** ![Kim](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@Kim](https://discuss.rubyonrails.org/u/Kim)\
**Post date:** [December 1, 2006, 5:44pm UTC](https://discuss.rubyonrails.org/t/select-tag-values-from-model/5310/2 "2006-12-01T17:44:54Z")

</div>

See following for detailed doc:

> **[ActionView::Helpers::FormOptionsHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000399)**
>
> Provides a number of methods for turning different kinds of containers into a set of option tags.

Here is an example:

\<%= select("object","selection",[option1, option2,...], {}, {:class =\> "class"}) %\>

Should give you a drop-down with the current value of @object.selection selected.

Help that helps

---

<div class="post-metadata">

**Author:** ![Rajkumar\_S](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@Rajkumar\_S](https://discuss.rubyonrails.org/u/Rajkumar_S)\
**Post date:** [December 2, 2006, 7:24am UTC](https://discuss.rubyonrails.org/t/select-tag-values-from-model/5310/3 "2006-12-02T07:24:09Z")

</div>

Thanks a lot for your reply, Kim.

> \<%= select("object","selection",[option1, option2,...], {}, {:class =\> "class"}) %\>

I want the dropdown for a model less form. So I do not have an "object". I did solve this by a an ugly way.

my form is:

\<%= form\_tag :action =\> :agent\_call\_list%\> &nbsp;&nbsp;\<%= @agent = Agent.find (:all, :order =\> "name") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collection\_select("blah", :agent\_id, @agent, :id, :name) -%\> &nbsp;&nbsp;&nbsp;\<%= submit\_tag -%\> \<%= end\_form\_tag %\>

in my controller, I give:

&nbsp;&nbsp;&nbsp;params['agent\_id'] = params['blah']['agent\_id'] if params.has\_key?("blah")

params['agent\_id'] is used by other forms and that's the place I expect the value to be. So I check if params['blah']['agent\_id'] is defined and if so, I copy it's value to params['agent\_id']

Ugly, but works. Though I would have preferred the value from the form in params['agent\_id']

Now if only I can select a particular value in my drop down list.

raj
