Reputation: 1275
Is there any way i can limit the results of an associated model?
This what i was trying to do :
<ul>
<% account.logins.slice(0,5).sort_by(&:login_date).reverse.each do |login| -%>
<li><%=h login.login_date.strftime("%d.%m.%Y")%></li>
<% end -%>
</ul>
I'm trying to get the last five logins of the account. I cant seem to do it with account.logins(:limit=>5)
Thanks !
Upvotes: 0
Views: 975
Reputation: 7841
or even shorter:
account.logins.all(:limit => 5, :order => 'login_date DESC')
=)
Upvotes: 2
Reputation: 18988
Try this:
account.logins.find(:all, :limit => 5, :order => 'login_date desc')
Upvotes: 1