gem 'friendly_id', '~> 5.1'
rails generate friendly_id
rails generate migration add_slug_to_posts slug:string:uniq
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged,
. . .
end
class PostsController < ApplicationController
def show
@post = Post.friendly.find(params[:id])
@postCreator = User.find(@post.user_id)
end
. . .
end
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]
. . .
end
Post.find(params[:id])