Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How To Use Limit With Rails Named_scope

DZone's Guide to

How To Use Limit With Rails Named_scope

·
Free Resource

class Competition < ActiveRecord::Base
  named_scope :limit, lambda { |num| { :limit => num } }
  named_scope :active, :conditions => {:status => Status::ACTIVE}
end


For example, if you want to get 5 active competitions


Competition.active.limit(5)
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}