ActsAsParam
Example
// In you model class Product
acts_as_param :name, :serial
end
// How To Use product = Product.create(:name => ‘name’,:serial => ‘serial’} product.to_param == ‘name’
product = Product.create(:name => nil,:serial => ‘serial’} product.to_param == ‘serial’
product = Product.create(:name => nil,:serial => nil} product.to_param == product.id
product.find_by_param(‘serial’) # find by product’s serial product.find_by_param(‘name’) # find by product’s name product.find_by_param(2) # find by Product’s primary key
product.find_by_param!(‘serial’) # raise ActiveRecord::RecordNotFound exception if not found
Copyright © 2010 Jinzhu / [email protected], released under the MIT license