load_and_authorize_resource in ApplicationController doesn't work with Devise #138

Closed
voxik opened this Issue Aug 31, 2010 · 1 comment

2 participants

@voxik

Hello,

I am trying to protect every controller of my application, therefore I have added "load_and_authorize_resource" into my application controller. However, now the Devise action for sign_in etc does not work. Here is entry from my log:

Started GET "/users/sign_in" for 127.0.0.1 at 2010-09-01 00:38:31 +0200
  Processing by Devise::SessionsController#new as HTML
Completed   in 9ms

NameError (uninitialized constant Session):


Rendered C:/Users/vita/.pik/rubies/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Users/vita/.pik/rubies/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (91.0ms)
Rendered C:/Users/vita/.pik/rubies/Ruby-192-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (109.0ms)

and the call stack:

activesupport (3.0.0) lib/active_support/inflector/methods.rb:124:in `block in constantize'
activesupport (3.0.0) lib/active_support/inflector/methods.rb:123:in `each'
activesupport (3.0.0) lib/active_support/inflector/methods.rb:123:in `constantize'
activesupport (3.0.0) lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
cancan (1.3.3) lib/cancan/controller_resource.rb:83:in `resource_class'
cancan (1.3.3) lib/cancan/controller_resource.rb:100:in `resource_base'
cancan (1.3.3) lib/cancan/controller_resource.rb:54:in `build_resource'
cancan (1.3.3) lib/cancan/controller_resource.rb:46:in `load_resource_instance'
cancan (1.3.3) lib/cancan/controller_resource.rb:30:in `load_resource'
cancan (1.3.3) lib/cancan/controller_resource.rb:24:in `load_and_authorize_resource'
cancan (1.3.3) lib/cancan/controller_resource.rb:9:in `block in add_before_filter'
activesupport (3.0.0) lib/active_support/callbacks.rb:446:in `_run__192464393__process_action__1059523234__callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.0) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.0) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.0) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.0) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.0) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.0) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.0) lib/action_controller/metal.rb:173:in `block in action'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:27:in `call'
actionpack (3.0.0) lib/action_dispatch/routing/mapper.rb:34:in `call'
rack-mount (0.6.12) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.12) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.12) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.12) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.12) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:492:in `call'
warden (0.10.7) lib/warden/manager.rb:35:in `block in call'
warden (0.10.7) lib/warden/manager.rb:34:in `catch'
warden (0.10.7) lib/warden/manager.rb:34:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/cookies.rb:287:in `call'
activerecord (3.0.0) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.0) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.0) lib/rails/application.rb:168:in `call'
railties (3.0.0) lib/rails/application.rb:77:in `method_missing'
railties (3.0.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/chunked.rb:15:in `call'
rack (1.2.1) lib/rack/handler/mongrel.rb:67:in `process'
mongrel-1.2.0.pre2-x86 (mingw32) lib/mongrel.rb:165:in `block in process_client'
mongrel-1.2.0.pre2-x86 (mingw32) lib/mongrel.rb:164:in `each'
mongrel-1.2.0.pre2-x86 (mingw32) lib/mongrel.rb:164:in `process_client'
mongrel-1.2.0.pre2-x86 (mingw32) lib/mongrel.rb:291:in `block (2 levels) in run'

I tried to use

skip_before_filter :load_and_authorize_resource

in devise-1.1.2\app\controllers\devise\sessions_controller.rb but without success. Could you help me please?

Vit

@ryanb
Owner

I don't recommend using load_and_authorize_resource in the ApplicationController. This is something that should be done in each controller separately because you may need to pass options to it to customize the behavior. Also not all controllers are RESTful which is the problem with the Devise controller.

The reason skip_before_filter does not work is because the before filter does not have a name, it's just done through a block which can't be skipped AFAIK.

If you're concerned about accidentally missing a controller, see issue #135 for a discussion on adding something to help.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment