Skip to content

Instantly share code, notes, and snippets.

@andregoncalves
Created June 18, 2009 17:15
Show Gist options
  • Select an option

  • Save andregoncalves/132026 to your computer and use it in GitHub Desktop.

Select an option

Save andregoncalves/132026 to your computer and use it in GitHub Desktop.
named scopes with dynamic find conditions
named_scope :active, :conditions => { :active => true }
named_scope :by_state, lambda { |state| { :conditions => { :active => state } } }
def self.search(params)
builder = Course.scope_builder
builder.by_state(params[:active]) if not params[:active].blank?
builder.all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment