Last active
June 27, 2020 21:21
-
-
Save 123ish/3a17e127a54dd2338bb92dffa840714b to your computer and use it in GitHub Desktop.
Friendly ID # /app/controllers/entries_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EntriesController < ApplicationController | |
before_action :set_entry, only: [:show, :update, :destroy, :edit] | |
def set_entry | |
@entry = Entry.find(params[:id]) | |
if !Rails.env.test? && @entry.friendly_id.present? && action_name=='show' | |
redirect_to action: action_name, id: @entry.friendly_id, status: 301 unless @entry.friendly_id == params[:id] | |
end | |
end | |
emd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment