Hi, I need your help with cancan.
I have this controler:
class RegistrationsController < Devise::RegistrationsController
I needed because I had to overwrite some methods.
I need to control the access to this controller because the administrator is the only that can add a new user.
How can I use load_and_authorize_resource?
My ability.rb file is: class Ability include CanCan::Ability
def initialize(user, controller_namespace) user ||= Usuario.new
case controller_namespace
when "Administrator"
if user.rol == 1
can :manage, Faq
can :manage, Tip
can :manage, Administrator::HomeTratamientoController
end
if user.rol == 2
can :manage, :admin_vacunas
can :manage, Registration
end
when "paciente"
if user.rol == 3
can :manage, Paciente::HomeController
end
else
can :read, :all
end
end
The model is usuario.rb
I don't have problem when the rol is 1 but when is 2, and I put the line:
load_and_authorize_resource
when in the registration controller I call the action new to add a new user by the adminstrator, show me the follow error:
Completed 500 Internal Server Error in 42ms (ActiveRecord: 5.1ms)
NameError - uninitialized constant Registration: activesupport (4.2.1) lib/active_support/dependencies.rb:533:in load_missing_constant' activesupport (4.2.1) lib/active_support/dependencies.rb:184:in
const_missing' activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in block in constantize' activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in
constantize' activesupport (4.2.1) lib/active_support/core_ext/string/inflections.rb:66:in constantize' cancancan (2.0.0) lib/cancan/controller_resource.rb:156:in
resource_class' cancancan (2.0.0) lib/cancan/controller_resource.rb:192:in resource_base' cancancan (2.0.0) lib/cancan/controller_resource.rb:80:in
build_resource' cancancan (2.0.0) lib/cancan/controller_resource.rb:61:in load_resource_instance' cancancan (2.0.0) lib/cancan/controller_resource.rb:35:in
load_resource' cancancan (2.0.0) lib/cancan/controller_resource.rb:12:in block in add_before_action' activesupport (4.2.1) lib/active_support/callbacks.rb:448:in
block in make_lambda' activesupport (4.2.1) lib/active_support/callbacks.rb:164:in block in halting' activesupport (4.2.1) lib/active_support/callbacks.rb:504:in
block in call' activesupport (4.2.1) lib/active_support/callbacks.rb:504:in call' activesupport (4.2.1) lib/active_support/callbacks.rb:92:in
_run_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:776:in _run_process_action_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in
process_action' actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (4.2.1) lib/active_support/notifications.rb:164:in
block in instrument' activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.1) lib/active_support/notifications.rb:164:in
instrument' actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in
process_action' activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.2.1) lib/abstract_controller/base.rb:137:in
process' actionview (4.2.1) lib/action_view/rendering.rb:30:in process' actionpack (4.2.1) lib/action_controller/metal.rb:196:in
dispatch' actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.1) lib/action_controller/metal.rb:237:in
block in action' actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in dispatch' actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in
serve' actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in serve' actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in
block in serve' actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in serve' actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' newrelic_rpm (3.16.1.320) lib/new_relic/rack/agent_hooks.rb:30:in
traced_call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' newrelic_rpm (3.16.1.320) lib/new_relic/rack/browser_monitoring.rb:32:in
traced_call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' newrelic_rpm (3.16.1.320) lib/new_relic/rack/developer_mode.rb:48:in
traced_call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' warden (1.2.6) lib/warden/manager.rb:35:in
block in call' warden (1.2.6) lib/warden/manager.rb:34:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/etag.rb:24:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/conditionalget.rb:25:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/head.rb:13:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context' rack (1.6.4) lib/rack/session/abstract/id.rb:220:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' activerecord (4.2.1) lib/active_record/query_cache.rb:36:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' activerecord (4.2.1) lib/active_record/migration.rb:378:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in
block in call' activesupport (4.2.1) lib/active_support/callbacks.rb:88:in _run_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:776:in
_run_call_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' better_errors (2.1.1) lib/better_errors/middleware.rb:84:in
protected_app_call' better_errors (2.1.1) lib/better_errors/middleware.rb:79:in better_errors_call' better_errors (2.1.1) lib/better_errors/middleware.rb:57:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' web-console (2.3.0) lib/web_console/middleware.rb:28:in
block in call' web-console (2.3.0) lib/web_console/middleware.rb:18:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' railties (4.2.1) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.1) lib/rails/rack/logger.rb:20:in
block in call' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in
tagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.1) lib/rails/rack/logger.rb:20:in
call' quiet_assets (1.1.0) lib/quiet_assets.rb:27:in call_with_quiet_assets' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/methodoverride.rb:22:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/runtime.rb:18:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/lock.rb:17:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' rack (1.6.4) lib/rack/sendfile.rb:113:in call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
call' railties (4.2.1) lib/rails/engine.rb:518:in call' railties (4.2.1) lib/rails/application.rb:164:in
call' newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call' rack (1.6.4) lib/rack/content_length.rb:15:in
call' thin (1.7.0) lib/thin/connection.rb:86:in block in pre_process' thin (1.7.0) lib/thin/connection.rb:84:in
pre_process' thin (1.7.0) lib/thin/connection.rb:53:in process' thin (1.7.0) lib/thin/connection.rb:39:in
receive_data' eventmachine (1.2.0.1) lib/eventmachine.rb:194:in run' thin (1.7.0) lib/thin/backends/base.rb:73:in
start' thin (1.7.0) lib/thin/server.rb:162:in start' rack (1.6.4) lib/rack/handler/thin.rb:19:in
run' rack (1.6.4) lib/rack/server.rb:286:in start' railties (4.2.1) lib/rails/commands/server.rb:80:in
start' railties (4.2.1) lib/rails/commands/commands_tasks.rb:80:in block in server' railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:in
server' railties (4.2.1) lib/rails/commands/commands_tasks.rb:39:in run_command!' railties (4.2.1) lib/rails/commands.rb:17:in
' bin/rails:9:in <top (required)>' spring (1.7.2) lib/spring/client/rails.rb:28:in
call' spring (1.7.2) lib/spring/client/command.rb:7:in call' spring (1.7.2) lib/spring/client.rb:30:in
run' spring (1.7.2) bin/spring:49:in <top (required)>' spring (1.7.2) lib/spring/binstub.rb:11:in
' bin/spring:13:in <top (required)>' bin/rails:3:in
'
Some body can help me please?
Aucun commentaire:
Enregistrer un commentaire