You've got several important syntax issues:
- Your routes seem malformed (you need to use
snake_case
rather than CamelCase
)
- You'll be better using the
exception_app
middleware hook to capture the exception
I would fix these as follows:
#config/routes.rb
resources :my_controllers #-> domain.com/my_controllers/:id
#app/controllers/my_controllers_controller.rb
Class MyController < ApplicationController
def show
@ingredient = MyController.find params[:id]
end
end
exceptions_app
I've actually written extensively about this here & written a gem here & there is a great github gist here
This will then give you the ability to capture any exceptions using the exceptions_app
middleware hook:
#config/application.rb
config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
This will allow you to route any exceptions through a separate controller called ExceptionController
:
#app/controllers/exception_controller.rb
Class ExceptionController < ApplicationController
layout 'application'
def show
@exception = env['action_dispatch.exception']
@status_code = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
@rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
respond_to do |format|
format.html { render :show, status: @status_code, layout: !request.xhr? }
format.xml { render xml: details, root: "error", status: @status_code }
format.json { render json: {error: details}, status: @status_code }
end
end
end
#app/views/exception/show.html.erb
Put what you want here
This will help you capture the exceptions - if you'd like to test in development, you should do this:
#config/environments/development.rb
config.consider_all_requests_local = false