You might want to look into has_one, in this case.
has_one :main_image, :class_name => "Image"
with a :conditions or :order or something specifying how to choose that
"main" image". It looks like you might not be using the has_many
relationship between Images and Categories correctly as well. I think you
mean to have Category has_many :images and Category.find(:all, :include =>
:images). ImageCategory looks a little Frankenmodel-y.
RSL
On 7/8/07, Daniel Mircea
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hello,
> I have image categories, and each category has an image. In my
> controller I''m using:
>
> @image_categories = ImageCategory.find(:all, :include => :images)
>
> and inside the view
>
> <% @image_categories.each do | category | -%>
> <%= category.name %>
> <% category.images.each do | image | -%>
> <%= image.name%>
> <% end -%>
> <% end -%>
>
> The code works, however i want to limit the display to only one image
> per category. So my question would be how can i combine :limit with the
> :include sintax ?
>
> Thanks.. any help would be really apreciated
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---