My initializer code.
When logged in as an unauthorized user I get redirected correctly once when the app is restarted but after that I am able to access the logged_exceptions page. I've tried moving this code to application.rb and development.rb (without Myapp::Application) with no success. No matter what I do I can't get the authorization to work more than once when the app is restarted. Any ideas?
I changed out
authorize_resource :class => false
and I'm just using
can :manage, :logged_exceptions
for some users in my ability class but it still only works once when I restart the application.
A simple :before_filter also only runs the first time in any environment. Could not isolate the cause. Anyone found something out?
No, I abandoned :logged_exceptions in favor of emailing exceptions. This will work for now but once we go public I'll need a more robust solution (one where a minor bug won't flood my inbox). At that point I'll re-evaluate :logged_exceptions and if I can't work out the issue, I'll check out something like hoptoad.
I'm having the exact same issue! before_filter only runs the first time. I'll post back if I find anything but any help is appreciated.
In my case I'm trying to integrate exception_logger with Spree, so ended up using app/controllers/logged_exceptions_controller_decorator.rb instead of an initializer & now my before_filter triggers every time.
I end up using HTTP Basic Authentication, looks like it's working well.
Metavida, how did you manage to do that?
My solution is probably pretty specific to using Spree. With spree installed, any file that you place in the app directory is automatically loaded or required as appropriate (I think they're using a Rails Engine somehow). Anyway, the following code worked well as a decorator for me.
# Sets the application name for the rss feeds
self.application_name = "RSS"
# Including spree auth
return if current_user && current_user.has_role?('admin')
respond_to do |format|
flash.now[:error] = I18n.t(:authorization_failure)
render 'shared/unauthorized', :layout => 'logged_exceptions'
# disallow return to login, logout, signup pages
disallowed_urls = [signup_url, login_url, destroy_user_session_path]
session["user_return_to"] = request.fullpath
redirect_to login_path and return
request_http_basic_authentication 'Web Password'
render :text => "Not Authorized \n", :status => 401