Module: Slug::ClassMethods

Defined in:
lib/slug.rb

Instance Method Summary collapse

Instance Method Details

Finder returning the matching content for a given permalink, or nil if none found. Notably, the content_type of the given permalink must match the target model’s class



37
38
39
40
41
# File 'lib/slug.rb', line 37

def find_by_permalink(permalink)
  find_by_permalink!(permalink)
rescue
  nil
end

#find_by_permalink!(permalink) ⇒ Object

Finder returning the matching content for a given permalink. Raises an ActiveRecord::RecordNotFound error if no match is found or if the content_type of the given permalink must match the target model’s class



46
47
48
49
50
# File 'lib/slug.rb', line 46

def find_by_permalink!(permalink)
  result = scoped_by_permalink(permalink).first
  raise ActiveRecord::RecordNotFound.new "Could not find Content for Permalink id=#{permalink.id}" if result.nil?
  result
end