I don’t know the fundamental thing that I’m misunderstanding here about
the find().
In my action “view_style” i want to list the sizes related to the the
style (which is the id I’m looking at).
My tables are sizes, styles and products, where products is a join
table with id, size_id and style_id, so that size\ “has_many :styles,
:through => products” and style “has_many :sizes, :through => products”
So i need to write something along the functionality of (this
pseudocode)
@sizes = find ( size_ids where style_id == params[:id])
in order that i can loop through the sizes in a select box in the view,
but for whatever reason, everything that I’ve tried has totally failed.
I’m at a loss and I’ve been stalled on this problem for a while now.
Can anyone help?
I don’t know the fundamental thing that I’m misunderstanding here about
the find().
In my action “view_style” i want to list the sizes related to the the
style (which is the id I’m looking at).
My tables are sizes, styles and products, where products is a join
table with id, size_id and style_id, so that size\ “has_many :styles,
:through => products” and style “has_many :sizes, :through => products”
So i need to write something along the functionality of (this
pseudocode)
@sizes = find ( size_ids where style_id == params[:id])
in order that i can loop through the sizes in a select box in the view,
but for whatever reason, everything that I’ve tried has totally failed.
I’m at a loss and I’ve been stalled on this problem for a while now.
Can anyone help?
So I assume you have a @style variable in your controller. To create
your select you can simply iterate through @style.sizes
<% @style.sizes.each do |size| %>
<%= size.name %>
<% end %>