Slugworth
Simple slug functionality for your ActiveRecord objects
Installation
Add this line to your application's Gemfile:
gem 'slugworth'
and then execute
bundle
or
install it yourself with
gem install slugworth
Usage
Getting started is easy! Just ensure that your model has a database column of type String
called slug
To use just add two declarations to your module and away you go!
class User < ActiveRecord::Base
include Slugworth
slugged_with :name
end
This provides most of the default slug functionality you would need.
- A finder
.find_by_slug
is provided. This will, of course, do what you expect and find a single record by the slug attribute provided. However, it will throw anActiveRecord::RecordNotFound
exception... if not found. #to_param
has been defined as a paramaterized version of the attribute declared toslugged_with
.- Validations stating that slug is present and unique in the database.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request