views:

18

answers:

1

I have reviewrequests that has many sitereviews. I can get at the count of the number of site reviews a given reviewrequest has in a view with: <%=h request.sitereviews.count.to_s %>

With each sitereview there's a text field - suggestions. Is there a way to get at say the last 5 sitereview.suggestions values as a single value? Something like: <%=h request.sitereviews.suggestions.last.5.to_s %>

+1  A: 

You could add this to request.rb

def latest_suggestions
  suggestions = []
  sitereviews.find(:all, :order => 'created_at desc', :limit => 5).each do |sr|
    suggestions << sr.suggestions
  end
  suggestions.join(',')
end

I'm guessing you mean that each site review has suggestions and you want to get the suggestions of the last 5 site reviews.

This is all pretty weird honestly, not sure why you would want this.

Graham