Module: ActsAsSluggable::FinderMethods
- Defined in:
- app/models/concerns/acts_as_sluggable.rb
Instance Method Summary collapse
Instance Method Details
#exists?(*args) ⇒ Boolean
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/concerns/acts_as_sluggable.rb', line 128 def exists?(*args) first = args.first || ''.freeze return super if first.kind_of?(Array) || first.kind_of?(Integer) slug = first.to_s if (slug.delete('^0-9'.freeze).length == slug.length) # The slug could be '400' (where(arel_table[:slug].eq(slug).or(arel_table[:id].eq(slug))).present? rescue false) else (find_by_slug(args).present? rescue false) end end |
#find(*args) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/concerns/acts_as_sluggable.rb', line 114 def find(*args) first = args.first || ''.freeze return super if first.kind_of?(Array) || first.kind_of?(Integer) slug = first.to_s if (slug.delete('^0-9'.freeze).length == slug.length) # The slug could be '400' find_by_slug(args) || find_by_id!(args) else find_by_slug!(args) end end |