Sha256: 44c888500f10a2240de7139077edf30e94d36f422bf63d063d2ba0f8a18c5463

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

[![Gem Version](https://badge.fury.io/rb/slugs.svg)](http://badge.fury.io/rb/slugs)
[![Code Climate](https://codeclimate.com/github/mmontossi/slugs/badges/gpa.svg)](https://codeclimate.com/github/mmontossi/slugs)
[![Build Status](https://travis-ci.org/mmontossi/slugs.svg)](https://travis-ci.org/mmontossis/slugs)
[![Dependency Status](https://gemnasium.com/mmontossi/slugs.svg)](https://gemnasium.com/mmontossi/slugs)

# Slugs

Minimalistic slugs inspired in friendly_id for rails.

## Install

Put this line in your Gemfile:
```ruby
gem 'slugs'
```

Then bundle:
```
$ bundle
```

## Configuration

Add the slug column to the tables of the models you want to have slugs:
```ruby
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:
```ruby
has_slug :prop
```

To concatenate the value of multiple fields:
```ruby
has_slug :prop1, :prop2, :prop3
```

If you need a very custom slug you can use a lambda, proc or block:
```ruby
has_slug proc { |record| "#{record.prop}-custom" }
```

To find a record by slug:
```ruby
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 [mmontossi](https://github.com/mmontossi).

## License

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slugs-2.0.0 README.md
slugs-1.3.2 README.md