Brandon Wright wrote:> 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| %>
<option value="<%= size.id %>"><%= size.name
%></option>
<% end %>
You can also use the option_for_select helper
<%= options_for_select(
@style.sizes.collect { |size|
[size.id, size.name]
}
) %>
It takes an array of [id, name] arrays to build you option tags for you.
options_for_select([[1, ''foo''], [2,
''bar'']])
#=> <option value="1">foo</option>
<option value="2">bar</option>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---