norman/friendly_id


FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.

http://norman.github.io/friendly_id/

License: MIT

Language: Ruby


Build Status Code Climate Inline docs

FriendlyId

For the most complete, user-friendly documentation, see the FriendlyId Guide.

FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Active Record. It lets you create pretty URLs and work with human-friendly strings as if they were numeric ids.

With FriendlyId, it's easy to make your application use URLs like:

http://example.com/states/washington

instead of:

http://example.com/states/4323454

Getting Help

Ask questions on Stack Overflow using the "friendly-id" tag, and for bugs have a look at the bug section

FriendlyId Features

FriendlyId offers many advanced features, including:

  • slug history and versioning
  • i18n
  • scoped slugs
  • reserved words
  • custom slug generators

Usage

Add this line to your application's Gemfile:

gem 'friendly_id', '~> 5.2.4' # Note: You MUST use 5.0.0 or greater for Rails 4.0+

And then execute:

bundle install

Add a slug column to the desired table (e.g. Users)

rails g migration AddSlugToUsers slug:uniq

Generate the friendly configuration file and a new migration

rails generate friendly_id

Note: You can delete the CreateFriendlyIdSlugs migration if you won't use the slug history feature. (Read more)

Run the migration scripts

rails db:migrate

Edit the app/models/user.rb file as the following:

class User < ApplicationRecord
  extend FriendlyId
  friendly_id :name, use: :slugged
end

Edit the app/controllers/users_controller.rb file and replace User.find by User.friendly.find

class UserController < ApplicationController
  def show
    @user = User.friendly.find(params[:id])
  end
end

Now when you create a new user like the following:

User.create! name: "Joe Schmoe"

You can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.

If you're adding FriendlyId to an existing app and need to generate slugs for existing users, do this from the console, runner, or add a Rake task:

User.find_each(&:save)

Bugs

Please report them on the Github issue tracker for this project.

If you have a bug to report, please include the following information:

  • Version information for FriendlyId, Rails and Ruby.
  • Full stack trace and error message (if you have them).
  • Any snippets of relevant model, view or controller code that shows how you are using FriendlyId.

If you are able to, it helps even more if you can fork FriendlyId on Github, and add a test that reproduces the error you are experiencing.

For more info on how to report bugs, please see this article.

Thanks and Credits

FriendlyId was originally created by Norman Clarke and Adrian Mugnolo, with significant help early in its life by Emilio Tagua. It is now maintained by Norman Clarke and Philip Arndt.

We're deeply grateful for the generous contributions over the years from many volunteers.

License

Copyright (c) 2008-2016 Norman Clarke and contributors, released under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project Statistics

Sourcerank 17
Repository Size 3.69 MB
Stars 5,099
Forks 539
Watchers 68
Open issues 70
Dependencies 17
Contributors 144
Tags 91
Created
Last updated
Last pushed

Top Contributors See all

Norman Clarke Philip Arndt Emilio Tagua Sergey Tsvetkov Peter Goldstein John Hawthorn Bruno Michel Adrián Mugnolo Andrew White Alex Coles Dave Gynn Ben Woosley Niall Burkley Jamie Davidson Tomás Arribas Alex Petrov Gagan Awhad Marc Rendl Ignacio bUg. Olivier Lacan

Packages Referencing this Repo

friendly_id4
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Ra...
Latest release 4.0.0.beta6 - Updated - 5.1K stars
mil_friendly_id
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Rails. It ...
Latest release 4.0.9.9 - Updated - 5.1K stars
friendly_id_globalize3
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Ra...
Latest release 3.2.1.6 - Updated - 5.1K stars
friendly_id
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Active Record. It ...
Latest release 5.2.5 - Updated - 5.1K stars
cmassimo-friendly_id
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Ra...
Latest release 3.0.4.2 - Published - 5.1K stars
geothird_friendly_id
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for Ruby on Rails. It ...
Latest release 4.0.9.8 - Updated - 5.1K stars

Recent Tags See all

5.2.5 December 30, 2018
5.2.4 April 24, 2018
5.2.3 September 21, 2017
5.2.2 September 14, 2017
5.2.0 April 09, 2017
5.2.1 April 09, 2017
5.0.5 January 16, 2015
5.1.0 January 16, 2015
5.1.0.beta.1 December 17, 2014
5.0.4 May 29, 2014
5.0.3 February 14, 2014
5.0.2 December 10, 2013
5.0.1 October 27, 2013
5.0.0 October 16, 2013
5.0.0.rc3 October 04, 2013

Interesting Forks See all

parndt/friendly_id
FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It a...
Ruby - MIT - Last pushed - 13 stars - 7 forks
chandresh/friendly_id
FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It a...
Ruby - MIT - Updated - 2 stars
kakra/friendly_id
FriendlyId is a plugin for Ruby on Rails which allows you to work with human-friendly strings as ...
Ruby - MIT - Last pushed - 2 stars
aub/friendly_id
FriendlyId is a plugin for Ruby on Rails which allows you to work with human-friendly strings as ...
Ruby - MIT - Updated - 2 stars
welltok/friendly_id
FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It a...
Ruby - MIT - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2018-12-30 02:31:52 UTC

Login to resync this repository