# Select in rhtml

**URL:** <https://www.ruby-forum.com/t/select-in-rhtml/93589>\
**Category:** Ruby\
**Created:** [April 4, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/select-in-rhtml/93589 "2006-04-04T23:54:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 4, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/select-in-rhtml/93589/1 "2006-04-04T23:54:31Z")

</div>

I’m trying to get a select box of categories to appear in my items  
views after I created everything using generate scaffold, but I can’t  
get the categories to appear in my forms.

class ItemsController \< ApplicationController  
def new  
@item = Item.new  
@category = Category.find\_all  
end

…

class Item \< ActiveRecord::Base  
belongs\_to :category  
end

class Category \< ActiveRecord::Base  
has\_many :items  
end

I found some news postings that said the select tag in my \_forms.rhtml  
was ‘object’, ‘attribute’, and ‘list\_items’, but I’ve tried several  
combinations and can’t get this right.

This is my ~/app/views/items/\_form.rhtml

Category  
\<%= select 'item', 'name', 'category' %\>

I think I’ve got the above wrong, but now sure how.

Here’s my database. Basically, all I want to do is assign a category to  
each item.

CREATE TABLE categories (  
id int unsigned NOT NULL auto\_increment,  
name varchar(32),  
description varchar(256),  
PRIMARY KEY (id)  
);

CREATE TABLE items (  
id int unsigned NOT NULL auto\_increment,  
name varchar(32),  
category\_id int unsigned,  
PRIMARY KEY (id)  
);
