select in rhtml

W

Wizumwalt

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

<p><label for="item_category_name">Category</label><br/>
<%= select 'item', 'name', 'category' %></p>

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)
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top