Hi,
I am trying to create 3 tables and link them to a fourth. I want table
Post_Type to be linked to tables: Supplies,Textbooks,Miscs. Below are
my table defs and models and controller. I only included a few because
they are similar. I would like be able to display all
supplies,textbooks,and miscs where post_type_id is equal to item_type.
I am very new to ruby and do not think i am going about this correctly.
create_table :post_types do |t|
t.column :Item_Type, :string
create_table :miscs do |t|
t.column :post_type_id, :string
t.column :Dept, :string
t.column :Class, :string
t.column :Qty, :integer
t.column :Price, :float
t.column :Descr, :text
t.column :Email, :string
create_table :supplies do |t|
t.column :post_type_id, :string
t.column :Dept, :string
t.column :Class, :string
t.column :Qty, :integer
t.column :Price, :float
t.column :Descr, :text
t.column :Email, :string
class Post_Type < ActiveRecord::Base
has_many :textbooks, :foreign_key => ‘post_type_id’
has_many :supplies, :foreign_key => ‘post_type_id’
has_many :miscs, :foreign_key => ‘post_type_id’
end
class Misc < ActiveRecord::Base
belongs_to :post_type,
:foreign_key=> ‘item_type’
end
Controller:::::
def test
@post_type = Post_Type.find(:all)
end
I have a rhtml file that displays the information below. It gives me an
error that qty is not defined.
<%= i.miscs.qty %> |
Please help. thanks.