-
Notifications
You must be signed in to change notification settings - Fork 0
This plugin defines ActiveRecord::Base#params_scope(params, options = {}).
License
hiroshi/params_scope
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ParamsScope =========== This plugin defines ActiveRecord::Base#params_scope(params, options = {}) and some other relatives. Examples ======= class User < ActiveRecord::Base named_scope :age, lambda{|age| {:conditions => ["age = ?", age]}} named_scope :city, lambda{|city| {:conditions => ["city = ?", city]}} named_scope :closed, lambda{|closed| {:conditions => ["closed = ?", closed]}} named_order_scope :order end class UsersController < ApplicationController def index # params may be {:age => "30", :city => "Tokyo"} @users = User.params_scope(params).find(:all, :defaults => {:closed => false}) # => User.closed(false).closed(false).age(30).city("Tokyo").find(:all) end end User.params_scope(:order => ["age", "asc", "updated_at, "desc"]).find(:all) # => User.find(:all, :order => "age ASC, updated_at DESC") TODOs ======= * Implicit scoping: If a given key is the name of a column, use it as a dynamic scope * Support range paramaters in some ways. Copyright (c) 2009 Hiroshi Saito (yakitara.com), released under the MIT license
About
This plugin defines ActiveRecord::Base#params_scope(params, options = {}).
Resources
License
Stars
Watchers
Forks
Releases
No releases published