vendredi 8 septembre 2017

Rails Cancan NameError - uninitialized constan

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:inconst_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:inconstantize' 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:inresource_class' cancancan (2.0.0) lib/cancan/controller_resource.rb:192:in resource_base' cancancan (2.0.0) lib/cancan/controller_resource.rb:80:inbuild_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:inload_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:inblock 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:inblock 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:inrun_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:inprocess_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:inblock 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:ininstrument' 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:inprocess_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:inprocess' actionview (4.2.1) lib/action_view/rendering.rb:30:in process' actionpack (4.2.1) lib/action_controller/metal.rb:196:indispatch' actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.1) lib/action_controller/metal.rb:237:inblock 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:inserve' actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in serve' actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:inblock 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:incall' 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:intraced_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:intraced_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:intraced_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:inblock 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context' rack (1.6.4) lib/rack/session/abstract/id.rb:220:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:inblock 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:incall' 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:incall' 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:incall' 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:inprotected_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:incall' 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:incall' 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:inblock 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:incall' 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:incall' railties (4.2.1) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.1) lib/rails/rack/logger.rb:20:inblock 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:intagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.1) lib/rails/rack/logger.rb:20:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' 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:incall' railties (4.2.1) lib/rails/engine.rb:518:in call' railties (4.2.1) lib/rails/application.rb:164:incall' 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:incall' thin (1.7.0) lib/thin/connection.rb:86:in block in pre_process' thin (1.7.0) lib/thin/connection.rb:84:inpre_process' thin (1.7.0) lib/thin/connection.rb:53:in process' thin (1.7.0) lib/thin/connection.rb:39:inreceive_data' eventmachine (1.2.0.1) lib/eventmachine.rb:194:in run' thin (1.7.0) lib/thin/backends/base.rb:73:instart' thin (1.7.0) lib/thin/server.rb:162:in start' rack (1.6.4) lib/rack/handler/thin.rb:19:inrun' rack (1.6.4) lib/rack/server.rb:286:in start' railties (4.2.1) lib/rails/commands/server.rb:80:instart' 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:inserver' 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:incall' spring (1.7.2) lib/spring/client/command.rb:7:in call' spring (1.7.2) lib/spring/client.rb:30:inrun' 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