module Humpyard::ActiveRecord::Has::TitleForUrl::ClassMethods
Public Instance Methods
find_by_title_for_url(url, options = {})
click to toggle source
# File lib/humpyard/active_record/has/title_for_url.rb 11 def find_by_title_for_url(url, options = {}) 12 options[:locale] ||= ::I18n.locale 13 14 unless Humpyard::config.locales.include? options[:locale].to_sym 15 options[:locale] = Humpyard::config.locales.first 16 end 17 18 if options[:skip_fallbacks] 19 locales = [options[:locale].to_sym] 20 else 21 locales = [options[:locale].to_sym] + (Humpyard::config.locales.map{|l| l.to_sym} - [options[:locale].to_sym]) 22 end 23 24 locales.each do |l| 25 #t = self.with_locale(l){find_first_by_translated_attr_and_locales(:title_for_url, url)} 26 t = self.translation_class.where('locale = ? AND title_for_url = ?', l.to_s, url.to_s).first 27 28 if t 29 return self.find(t["#{self.name.underscore.gsub('/', '_')}_id"]) 30 end 31 end 32 33 nil 34 end