Sounds like you want something like has_many :through.
class Design < ActiveRecord::Base
has_many :sizes, :through => :availability
end
class Size < ActiveRecord::Base
has_many :designs, :through => :availability
end
class Availability < ActiveRecord::Base
#You might have to set the table name here.
belongs_to :design
belongs_to :size
end
In the availability table you’ll have a design_id field and a size_id field as well as another field that’s a number, telling you how many of a certain design and size are available.
Hi, I would recommend reading chapters 16, 17, and 18 of the “Agile Web Development with Rails 2ed (AWDwRv2)”. This should give you a very good foundation from witch to build from.
i set up the relationship as Ryan suggested, and it looks as if it's
ready to go. now i'm making a nested unordered list so we can see [and
edit] what designs and sizes we've got in stock.
*Design1
*S [ 6] <---- text field
*M [ ]
*L [ 9]
*XL [ 12]
*Design2
*S [ 3]
*M [ 8]
*L [ 9]
*XL [ 12]
........
can this all be done in the one form? i'm not sure how to grab the
corresponding availability, and what if it hasn't been created yet??
i thought something like:
<% form_for(@availability) do |f| %>
<ul>
<% for design in @designs %>
<li>
<%=h design.name %>
<ul>
<% for size in @sizes %>
<li><%= size.name %> [TEXT FIELD FOR NUM IN STOCK]</li>
<% end %>
</ul>
</li>
<% end %>
</ul>
<% end %>
all the SQL is right there in my head! still trying to grasp the whole
object oriented thing.