I’m trying to do the following in rails 3:
@groups_active = Group.active_groups(current_user)
active_groups is a scope. This query works fine. I then want to do the following:
if @groups_active.count > 9
@groups_active[0..10]
end
Meaning if there are more than 10 items in the @groups_active, take just the TOP 10, which thanks to the scope ordering are the most active.
Suggestions? Thanks
I’m not sure what your problem is. You can limit the number of results from a query with
Model.your_scope.limit(10), and if it is a query that doesn’t work with a SQLLIMITthen you can useModel.your_scope.first(10). That’s anArray#first, which accepts a fixnum argument to be used as expected…