I have a user controller that, if I want to, I can rescue the error if no user is found and redirect them to the appropriate page. But I would like to only use the rescue_from
method only on certain routes instead of all the routes. So, pretty much something similar to
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found, except: [:new, :edit]
Is there a way to do this? Help is appreciated!
class UserController < ApplicationController
before_action :get_user
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
def show
end
def new
end
def create
end
def edit
end
def update
end
private
def get_user
User.find(params[:id])
end
def record_not_found
redirect_to user_path, error: "Sorry, no user found."
end
end