I downloaded the friendly_id gem in order to make my URLs more user friendly. To honor their instructions, I am asking this here instead of on GitHub.
Here is my Show Method
def show
@movie = Movie.friendly.find(params[:id])
end
This is in compliance with their documentation
Finders are no longer overridden by default. If you want to do friendly finds, you must
do Model.friendly.find rather than Model.find. You can however restore FriendlyId
4-style finders by using the :finders addon:
In my Model.rb file, I have the following
extend FriendlyId
friendly_id :title, use: :slugged
From their documentation
friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
also from their documentation
def set_restaurant
@restaurant = Restaurant.friendly.find(params[:id])
end
For reference, here is their guide.
Granted, I haven't generated a migration yet, because I had already created the table.
I'm unsure of what my next step should be?
Thank you for your help.
You need to run a migration to add the slug column to your table:
class AddSlugToMovies < ActiveRecord::Migration
def change
add_column :movies, :slug, :string, unique: true
end
end
Run rake db:migrate
, and then in your rails console run Move.find_each(&:save)
to populate the slug column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With