Reputation: 1375
I'm using Rails 3.2.3 with ActiveResource. I have an issue in production that says:
ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found.
So I tried to treat it the same way I treat ActiveRecord::RecordNotFound
:
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound do |e|
render_404
end
rescue_from ActiveResource::ResourceNotFound do |e|
render_404
end
def render_404
respond_to do |type|
type.html { render template: 'shared/404_not_found', layout: 'application', status: '404 Not Found' }
type.all { render nothing: true, status: '404 Not Found' }
end
end
end
But now, when I deploy, I get an error telling me that:
/apps/com.example/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.3/lib/active_admin/namespace.rb:191:in `eval': uninitialized constant ActiveResource::ResourceNotFound (NameError)
I don't really get it. I tried with a if defined?(ActiveResource::ResourceNotFound)
but then it falls back to the previous behavior.
Any idea of how to treat this issue ?
Thanks !
EDIT: For the moment I used the following code but I'm not really happy with it.
rescue_from Exception do |e|
e.is_a?(ActiveResource::ResourceNotFound) ? render_404 : raise
end
Upvotes: 1
Views: 1455
Reputation: 16092
Heh, ignore my comment I figured out a solution:
rescue_from "ActiveResource::ResourceNotFound" do |e|
render_404
end
Put the exception in quotes so it doesn't try to evaluate it on startup (when, I assume, ActiveResource hasn't loaded yet)
Upvotes: 2