M
M
mlwrm2016-04-19 19:33:08
Ruby on Rails
mlwrm, 2016-04-19 19:33:08

Why doesn't friendly_id work?

added gem

gem 'friendly_id', '~> 5.1'

fulfilled
rails generate friendly_id
rails generate migration add_slug_to_posts slug:string:uniq

model
class Post < ActiveRecord::Base
  extend FriendlyId
  friendly_id :title, use: :slugged,
. . . 
end

controller
class PostsController < ApplicationController
   def show
    @post = Post.friendly.find(params[:id])
    @postCreator = User.find(@post.user_id)
  end
. . .
end

It is paradoxical that everything works through the console
eb87736674444506891bb92ab2bfbbc9.png
And here's
32e60db957a14c6fa98082f2561ec750.png
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mlwrm, 2016-04-19
@malworm

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

I also removed .friendly from the action and just use
I don't quite understand how, but it helped.
I hope it will be useful to someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question