Module: ActsAsSlugged::FinderMethods

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

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/concerns/acts_as_slugged.rb', line 167

def find(*args)
  return super unless args.length == 1
  return super if block_given?

  reloading = instance_variable_get(:@_effective_reloading)
  reloading ||= self.class.instance_variable_get(:@_effective_reloading)
  reloading ||= klass.instance_variable_get(:@_effective_reloading) if respond_to?(:klass)

  return find_by_id(args.first) if reloading

  find_by_slug(args.first) || raise(::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with 'slug'=#{args.first}"))
end

#find_by_slug_or_id(*args) ⇒ Object



180
181
182
# File 'app/models/concerns/acts_as_slugged.rb', line 180

def find_by_slug_or_id(*args)
  where(slug: args.first).or(where(id: args.first)).first
end