module Concerns::Category::FriendlyParam::ClassMethods

Public Instance Methods

count_by_friendly_param(param) click to toggle source
# File app/models/concerns/category/friendly_param.rb, line 7
def count_by_friendly_param(param)
  ::Category.count :conditions => [ "friendly_param = ?", param ]
end
find_by_friendly_param(param) click to toggle source
# File app/models/concerns/category/friendly_param.rb, line 11
def find_by_friendly_param(param)
  category_count = count_by_friendly_param(param)
  case category_count
  when 0
    nil
  when 1
    ::Category.first(:conditions => ['friendly_param = ?', param])
  else
    raise Concerns::Category::AmbiguousParamException, "#{category_count} occurrences of #{param}"
  end
end