I have a ActiveRecord query for example like this:
@result = stuff.limit(10)
where stuff is a active record query with where clauses, order by,
The scope would look like any other (although you may prefer a class method), e.g.,
class Stuff < ActiveRecord::Base
def self.lim
limit(3)
end
end
> Stuff.lim.all
=> [#,
#,
#]
> Stuff.all.length
=> 8
If you always (or "almost" always) want that limit, use a default scope:
class Stuff < ActiveRecord::Base
attr_accessible :name, :hdfs_file
default_scope limit(3)
end
> Stuff.all
=> [#,
#,
#]
> Stuff.all.length
=> 3
To skip the default scope:
> Stuff.unscoped.all.size
=> 8