Joshua Kappers <lists@...> writes:

> 
> Essentially, I want to achieve something like this:
> http://pastie.org/private/0yuhxeqyheqov3pzkhnga
> 
> Item model that can contain many Items that are required to create that
> Item.
> 
> I'm new to rails, and having a hard time figuring out how to make this
> happen. Any guidance, is greatly appreciated.
> 


# Item

item_id,  name
1, Wood
2, Copper Ore
3, Copper Sword


# ItemComponents

compound_id, item_id, amount
3,                   1,         5
3,                   2,         8

# Models

Item << ActiveRecord::Base
  has_many :item_components
end

ItemComponent < ActiveRecord:Base
  belongs_to :item
  belongs_to :compound
end

Compound << ActiveRecord::Base
  has_many :item_components
end


Andf change the view code to work:

@item.find(3).item_components.each do |component|
  <%= item.name %> <%= component.amount %>
end
 


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to