Question regarding select_tag

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

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

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

select_tag(“id”, options_from_collection_for_select(@excersises,
“title”, “id”))

hth :slight_smile:

This worked, thanks.

Chris

On 7/10/07, Shai R. [email protected] wrote:

select_tag(“id”, options_from_collection_for_select(@excersises,
“title”, “id”))


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