Module: Slugalicious::ClassMethods
- Defined in:
- lib/slugalicious.rb
Overview
Methods added to the class when this module is included.
Instance Method Summary collapse
-
#find_from_slug(slug, scope = nil) ⇒ ActiveRecord::Base?
Locates a record matching a given slug.
-
#find_from_slug!(*args) ⇒ Object
Identical to #find_from_slug, but raises an exception if the object is not found.
-
#find_from_slug_path(path) ⇒ ActiveRecord::Base
Locates a record from a given path, that consists of a slug and its scope, as would appear in a URL path component.
Instance Method Details
#find_from_slug(slug, scope = nil) ⇒ ActiveRecord::Base?
Locates a record matching a given slug.
49 50 51 |
# File 'lib/slugalicious.rb', line 49 def find_from_slug(slug, scope=nil) Slug.from_slug(self, scope, slug).first.try!(:sluggable) end |
#find_from_slug!(*args) ⇒ Object
Identical to #find_from_slug, but raises an exception if the object is not found.
36 37 38 |
# File 'lib/slugalicious.rb', line 36 def find_from_slug!(*args) find_from_slug(*args) || raise(ActiveRecord::RecordNotFound) end |
#find_from_slug_path(path) ⇒ ActiveRecord::Base
Locates a record from a given path, that consists of a slug and its scope, as would appear in a URL path component.
61 62 63 64 65 |
# File 'lib/slugalicious.rb', line 61 def find_from_slug_path(path) slug = path.split('/').last scope = path[0..(-(slug.size + 1))] find_from_slug slug, scope end |