# Question regarding select\_tag

**URL:** <https://www.ruby-forum.com/t/question-regarding-select-tag/108966>\
**Category:** Rails\
**Created:** [July 10, 2007, 4:30am UTC](https://www.ruby-forum.com/t/question-regarding-select-tag/108966 "2007-07-10T04:30:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Johnston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Chris\_Johnston](https://www.ruby-forum.com/u/Chris_Johnston)\
**Post date:** [July 10, 2007, 4:30am UTC](https://www.ruby-forum.com/t/question-regarding-select-tag/108966/1 "2007-07-10T04:30:22Z")

</div>

Hello,

I have the following code in the little application that I am writing.  
It is  
basically taken directly out of the Agile Web D. with Rails  
book.

In the controller:

```
@exercises = Exercise.find(:all).map { |f| [f.name, f.id] }

```

And in the view

\<% form\_tag :action =\> ‘create’ do %\>  
…  
Exercise: \<%= select\_tag(:id,  
@exercises)  
%\>  
\<% end %\>

## And this is what it is producing: Exercise: Incline Dumbbell Press1Push-up2Squats3Incline Dumbbell Press4Push-up5Squats6asdfasdf7another test8asdfasdfasdfasdfasdf12349asdfasdfasdfasdfasdf123410111test exercise

no description12testing error stuffs13

This is obviously not what I was expecting. It makes it really hard to  
pick  
something from what I thought would be a nice little drop down select  
widget.

What am I doing wrong?

## Thanks, Chris

[www.fuzzylizard.com](http://www.fuzzylizard.com)

You know you’ve achieved perfection in design, Not when you have nothing  
more to add, But when you have nothing more to take away.  
– Antoine de Saint-Exupery

---

<div class="post-metadata">

**Author:** ![Chris\_Johnston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Chris\_Johnston](https://www.ruby-forum.com/u/Chris_Johnston)\
**Post date:** [July 10, 2007, 10:04am UTC](https://www.ruby-forum.com/t/question-regarding-select-tag/108966/2 "2007-07-10T10:04:38Z")

</div>

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000604](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000604)

select\_tag creates the tag, but you need to add in the  
options you want…do something like this:

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000511](http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000511)

select\_tag(“id”, options\_from\_collection\_for\_select(@excersises,  
“title”, “id”))

hth 🙂

---

<div class="post-metadata">

**Author:** ![Chris\_Johnston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Chris\_Johnston](https://www.ruby-forum.com/u/Chris_Johnston)\
**Post date:** [July 10, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/question-regarding-select-tag/108966/3 "2007-07-10T16:08:48Z")

</div>

This worked, thanks.

Chris

On 7/10/07, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> select\_tag(“id”, options\_from\_collection\_for\_select(@excersises,  
> “title”, “id”))

–  
[www.fuzzylizard.com](http://www.fuzzylizard.com)

You know you’ve achieved perfection in design, Not when you have nothing  
more to add, But when you have nothing more to take away.  
– Antoine de Saint-Exupery
