Project

chain-boy

0.0
No commit activity in last 3 years
No release in over 3 years
Dynamic delegator - created from the information demonstrated in RailsCasts episode 212
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Install the gem¶ ↑

gem install chain-boy

Rails Gemfile¶ ↑

gem 'chain-boy'

So what does it do?¶ ↑

Turn this :

def self.search(params)
  products = Product.scoped
  products = products.where("name like ?", "%" + params[:name] + "%") if params[:name]
  products = products.where("price >= ?", params[:price_gt]) if params[:price_gt]
  products = products.where("price <= ?", params[:price_lt]) if params[:price_lt]
  products
end

Info this :

#outside of a rails app you will need to require 'chain-boy'

def self.search(params)
  products = DynamicDelegator.new(Product.scoped)
  products.where("name like ?", "%" + params[:name] + "%") if params[:name]
  products.where("price >= ?", params[:price_gt]) if params[:price_gt]
  products.where("price <= ?", params[:price_lt]) if params[:price_lt]
  products
end