Module: Railslove::Plugins::FindByParam::SingletonMethods
- Defined in:
- lib/find_by_param.rb
Instance Method Summary collapse
-
#find_by_param(value, args = {}) ⇒ Object
Search for an object by the defined permalink column.
-
#find_by_param!(value, args = {}) ⇒ Object
Like
find_by_param
but raises anActiveRecord::RecordNotFound
error if nothing is found - similar to find().
Instance Method Details
#find_by_param(value, args = {}) ⇒ Object
Search for an object by the defined permalink column. Similar to find_by_login
. Returns nil
if nothing is found. Accepts an options hash as second parameter which is passed on to the rails finder.
107 108 109 110 111 112 113 114 115 |
# File 'lib/find_by_param.rb', line 107 def find_by_param(value, args={}) if [:prepend_id] param = "id" value = value.to_i else param = [:param] end self.send("find_by_#{param}".to_sym, value, args) end |
#find_by_param!(value, args = {}) ⇒ Object
Like find_by_param
but raises an ActiveRecord::RecordNotFound
error if nothing is found - similar to find().
Accepts an options hash as second parameter which is passed on to the rails finder.
125 126 127 128 129 130 |
# File 'lib/find_by_param.rb', line 125 def find_by_param!(value, args={}) param = [:param] obj = find_by_param(value, args) raise ::ActiveRecord::RecordNotFound unless obj obj end |