Module: ActsAsSluggable::FinderMethods

Defined in:
app/models/concerns/acts_as_sluggable.rb

Instance Method Summary collapse

Instance Method Details

#exists?(*args) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/models/concerns/acts_as_sluggable.rb', line 126

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



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/concerns/acts_as_sluggable.rb', line 112

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