Module: SimpleSlug::ModelAddition::ClassMethods

Defined in:
lib/simple_slug/model_addition.rb

Instance Method Summary collapse

Instance Method Details

#simple_slug_find(id_param) ⇒ Object Also known as: friendly_find



45
46
47
48
49
50
51
52
# File 'lib/simple_slug/model_addition.rb', line 45

def simple_slug_find(id_param)
  return unless id_param
  if id_param.is_a?(Integer) || id_param =~ SimpleSlug::NUMBER_REGEXP
    find(id_param)
  else
    send(simple_slug_adapter.finder_method, simple_slug_adapter.column_name => id_param) or simple_slug_history_find(id_param)
  end
end

#simple_slug_history_find(slug, locale = I18n.locale) ⇒ Object



54
55
56
# File 'lib/simple_slug/model_addition.rb', line 54

def simple_slug_history_find(slug, locale=I18n.locale)
  find(SimpleSlug::HistorySlug.find_by!(locale: (locale if simple_slug_adapter.valid_locale?(locale)), slug: slug).sluggable_id)
end