Hello,
I’m trying to implement something like the following scenario. I’ve got
“Alloys” (blends of metals), “Metals” and “Percentages” I want to
implement
this using a join model, not using a has_and_belongs_to_many
relationship.
(If i’m wrong about that, let me know).
Basically, i have the following tables:
Metals
id
name
Alloys
id
name
Percentages
alloy_id
metal_id
percent
And the following code in my models:
Alloy
has_many :metals, :through => :percentages
has_many :percentages, :dependent => true
Metal
has_many :alloys, :through => :percentages
has_many :percentages, :dependent => true
Percentage
belongs_to :alloy
belongs_to :metal
Now, I’m trying to make what boils down to an interface for people to
create
new alloys. Alloys can have up to a predefined amount of metals (not
infinite, like tags, but it does need to be extendable, otherwise i
could go
for a less elegant database design and throw out all the relational
database
ideas. In other words, i could just make the table “Alloys” have
Metal1,
Percentage1, Metal2, Percentage2, etc. as columns in the table).
Ok, so, what’s the right way to do this? I was hoping to be able to put
in,
say, 6 (where you can have 6 metals) select boxes, each listing all the
metals, and have 6 text fields to allow the user to type in the
percentage
of each.
Just as a start, i tried to do something like:
<%= select(‘alloy’, ‘NNNNN’, Metal.find(:all, :order => “name”).map
{|v| [
v.name, v.id]}) %>
where NNNNN is any number of things i’ve tried, all of which give me a
“NoMethodError in Alloys#new” error.
Am I on the fringes of rails? Or am I so newb it hurts? Any help would
be
appreciated.
-Matt Miller