Answer the question
In order to leave comments, you need to log in
Why doesn't friendly_id work?
added gem
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
Answer the question
In order to leave comments, you need to log in
Solved the problem by adding :finders to the use array:
Now it looks like this
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]
. . .
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question