Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Minimalistic slugs inspired in friendly_id for rails.
Ruby HTML JavaScript CSS
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
slugs.gemspec

README.md

Gem Version Code Climate Build Status Dependency Status

Slugs

Minimalistic slugs inspired in friendly_id for rails.

Install

Put this line in your Gemfile:

gem 'slugs'

Then bundle:

$ bundle

Configuration

Add the slug column to the tables of the models you want to have slugs:

t.string :slug

Update your db:

rake db:migrate

NOTE: If you are using translatable_records you need to place the column in the translations table.

Usage

Use has_slug in your models to define what the slug will be:

If you want to use the value of one field:

has_slug :prop

To concatenate the value of multiple fields:

has_slug :prop1, :prop2, :prop3

If you need a very custom slug you can use a lambda, proc or block:

has_slug proc { |record| "#{record.prop}-custom" }

To find a record by slug:

Model.slugged.find 'slug'

NOTE: All the path and url helpers will start using the slug by default.

Credits

This gem is maintained and funded by museways.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

Something went wrong with that request. Please try again.