Module: Cowtech::RubyOnRails::Extensions::AR::ClassMethods
- Defined in:
- lib/cowtech/extensions.rb
Instance Method Summary collapse
- #find_or_create(oid, attributes = nil) ⇒ Object
- #per_page ⇒ Object
- #random ⇒ Object
- #safe_find(oid) ⇒ Object
Instance Method Details
#find_or_create(oid, attributes = nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/cowtech/extensions.rb', line 22 def find_or_create(oid, attributes = nil) begin self.find(oid) rescue ActiveRecord::RecordNotFound self.new(attributes) end end |
#per_page ⇒ Object
43 44 45 |
# File 'lib/cowtech/extensions.rb', line 43 def per_page 25 end |
#random ⇒ Object
38 39 40 41 |
# File 'lib/cowtech/extensions.rb', line 38 def random c = self.count c != 0 ? self.find(:first, offset: rand(c)) : nil end |
#safe_find(oid) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/cowtech/extensions.rb', line 30 def safe_find(oid) begin rv = self.find(oid) rescue ActiveRecord::RecordNotFound nil end end |