Controller/View concerns


I have 2 questions.


@websites = Website.find(:all)


<% for website in @websites %>


<%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.

  1. 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.

On Feb 9, 5:40 am, Pablo [email protected] wrote:


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}

You can use .find on the collection.

website.website_photos.find :all, :limit => 2