Module: TheFriendlyId::Base::ClassMethods
- Defined in:
- lib/the_friendly_id.rb
Instance Method Summary collapse
Instance Method Details
#friendly_first(id) ⇒ Object
113 114 115 |
# File 'lib/the_friendly_id.rb', line 113 def friendly_first id friendly_where(id).first end |
#friendly_where(id) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/the_friendly_id.rb', line 97 def friendly_where id if TheFriendlyId::Base.int?(id) where(id: id) elsif id.is_a? Array ids = id.map(&:to_slug_param) where(slug: ids) elsif TheFriendlyId::Base.friendly?(id) where(friendly_id: id) elsif TheFriendlyId::Base.short?(id) by_slug = where(slug: id.to_slug_param) by_slug.present? ? by_slug : where(slug: id.to_slug_param) else where(slug: id.to_slug_param) end end |