Skip to content

Instantly share code, notes, and snippets.

@123ish
Last active June 27, 2020 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 123ish/3a17e127a54dd2338bb92dffa840714b to your computer and use it in GitHub Desktop.
Save 123ish/3a17e127a54dd2338bb92dffa840714b to your computer and use it in GitHub Desktop.
Friendly ID # /app/controllers/entries_controller.rb
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