Forum: Ruby on Rails Controller/View concerns

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
734a7bce0ec28ecc63ab0bc92cfa3182?d=identicon&s=25 Pablo (Guest)
on 2007-02-09 11:40

I have 2 questions.



@websites = Website.find(:all)


<% for website in @websites %>
<div id="portfolio_item">


<%for photo in website.website_photos%>
<%= image_tag photo.public_filename, :size => photo.image_size %>


So, i have websites, and they have many website_photos. This code works
fine but how can i display for example 2 first photos, not loop through
all of them, without putting the logic in the view. I could only achieve
this by putting some  variables in the view.

2. My second question is about general way how to sort stuff. My first
idea was to sort by id of the photo, or maybe make a special boolean
field in the table and if it's true the photo will be listed on the main
page, otherwise not.
47c3920e98510f592b2e8dcf8bbaf07f?d=identicon&s=25 surfivor (Guest)
on 2007-02-09 12:39
(Received via mailing list)
On Feb 9, 5:40 am, Pablo <> wrote:
> view:
> </div>
> page, otherwise not.
> --
> Posted via

you could create a helper, otherwise something like

for idx in 0..1
  if @website[idx]

Not sure what the other question you are asking is. You can sort:
list.sort {|x,y| x.fld <=> y.fld}
C941170ba5ca038b89b8407c83fb23c2?d=identicon&s=25 Berin Loritsch (Guest)
on 2007-02-09 16:04
(Received via mailing list)
You can use .find on the collection.

website.website_photos.find :all, :limit => 2
This topic is locked and can not be replied to.