Module: FriendlyId::Globalize::FinderMethods
- Defined in:
- lib/friendly_id/globalize.rb
Instance Method Summary (collapse)
-
- (Object) find_one(id)
protected
FriendlyId overrides this method to make it possible to use friendly id's identically to numeric ids in finders.
Instance Method Details
- (Object) find_one(id) (protected)
FriendlyId overrides this method to make it possible to use friendly id's identically to numeric ids in finders.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/friendly_id/globalize.rb', line 95 def find_one(id) return super if id.unfriendly_id? found = where(@klass.friendly_id_config.query_field => id).first found = includes(:translations). where(translation_class.arel_table[:locale].in([I18n.locale, I18n.default_locale])). where(translation_class.arel_table[@klass.friendly_id_config.query_field].eq(id)).first if found.nil? if found # Reload the translations for the found records. found.tap { |f| f.translations.reload } else # if locale is not translated fallback to default locale super end end |