Forum: Ruby on Rails Problem with select helpers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ana B. (Guest)
on 2006-04-06 23:29
Hi guys,

Im doing a todo list in wich every todo item belongs to a category so at
the time of create i want a select dropdown to let me choose the
category for the new todo item.
I have two models, todo and category(wich contains a name field), all
goes fine the problem is that i cant fill the select with the names in
the category table, here are the code im using, i tried many ways to
make the select work but without success:
http://rafb.net/paste/results/ywoI5816.html

Hope someone can help with this :)
Adam B. (Guest)
on 2006-04-06 23:38
Maybe I'm missing something but you never defined the variable
@categories. Add this line to the list action:

@categories = Category.find(:all, :order => "name")
Ana B. (Guest)
on 2006-04-06 23:43
Adam B. wrote:
> Maybe I'm missing something but you never defined the variable
> @categories. Add this line to the list action:
>
> @categories = Category.find(:all, :order => "name")

done, i added the @categories = Category.find(:all, :order => "name")
line to the list action, but now i get this error:

undefined method `name' for #<Array:0x3ab2808>

i think the problem its in the select helper sintax because if i use:

<SELECT NAME="myselect">
        <% @category.each do |@category| %>
	<OPTION VALUE="<%= @category.name %>"><%= @category.name %>
	<% end %>
</SELECT>

there are no errors but i want to optimize my code at best.
This topic is locked and can not be replied to.