Stack Overflow en español Asked by josedes on December 31, 2020
Estoy usando Cancancan y cuando llamo a la acción de index
funciona bien, pero cuando intento llamar a new
me muestra:
Completed 500 Internal Server Error in 10ms (ActiveRecord: 1.2ms)
ArgumentError – wrong number of arguments (given 1, expected 0):
actionpack (4.2.1) lib/action_controller/metal.rb:131:ininitialize'
initialize’ actionview (4.2.1) lib/action_view/layouts.rb:355:in
actionpack (4.2.1) lib/action_dispatch/routing/url_for.rb:104:in
initialize' cancancan (2.0.0)
new’
lib/cancan/controller_resource.rb:80:in
No entiendo que sucede, alguien me puede ayudar
Este es mi applicationController.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include CodigosGenerales
before_action :cargarOpcionesDelPrincipal
layout :colocar_layout
helper_method :resource, :resource_name, :devise_mapping
before_filter do
resource = controller_path.singularize.gsub('/', '_').to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.json { head :forbidden, content_type: 'text/html' }
format.html { redirect_to root_path, alert: 'No tiene autorización para acceder' }
format.js { head :forbidden, content_type: 'text/html' }
end
end
def current_ability
controller_name_segments = params[:controller].split('/')
controller_name_segments.pop
controller_namespace = controller_name_segments.join('/').camelize
Ability.new(current_usuario, controller_namespace)
#Ability.new(current_usuario)
end
def resource_name
:usuario
end
def resource
@resource ||= Usuario.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:usuario]
end
private
def after_sign_out_path_for(resource_or_scope)
new_usuario_session_path
end
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me) }
devise_parameter_sanitizer.permit(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
devise_parameter_sanitizer.permit(:account_update) {
|u| u.permit(:nombre,
:apellido,
:email,
:password,
:password_confirmation,
:current_password,
:cedula,
:numero_excel,
:historia,
:estado,
:apellido,
:telefono_habitacion,
:telefono_trabajo,
:celular1,
:celular2,
:email2,
:fecha_nacimiento,
:ava,
:hong,
:berm,
:john,
:asp,
:blom,
:rol ) }
end
end
este es mi archivo model/ability.rb
class Ability
include CanCan::Ability
def initialize(user, controller_namespace)
user ||= Usuario.new # guest user (not logged in)
can :manage, :welcome_con
case controller_namespace
when "Administrator"
if user.rol == 1
can :manage, Administrator::FaqsController
can :manage, Administrator::TipsController
end
if user.rol == 2
can :manage, :admin_vacunas
can :manage, Administrator::ConfigurationsController
can :manage, Administrator::ContactosController
can :manage, Administrator::HomeTratamientoController
can :manage, Administrator::VacunasController
end
when "paciente"
if user.rol == 3
can :manage, Paciente::HomeController
end
else
can :read, :all
end
end
end
Y este es mi controlador:
class Administrator::FaqsController < ApplicationController
include CodigosGenerales
before_filter :authenticate_usuario!
before_action :cargarOpcionesDelPrincipal
load_and_authorize_resource :class => Administrator::FaqsController
layout "administrator"
def index
@faqs = Faq.all.order('created_at desc')
if @faqs.empty?
flash.now[:warning] = "Aún no se han creado preguntas y respuestas"
end
end
def show
@faq = Faq.find(params[:id])
end
def new
@faq = Faq.new
end
def edit
@faq = Faq.find( params[:id] )
end
def create
@faq = Faq.new(faq_params)
@faq.usuario_id = current_usuario.id
respond_to do |format|
if @faq.save
format.html { redirect_to administrator_faq_path(@faq), notice: 'La pregunta fue creada exitosamente' }
format.json { render :show, status: :created, location: @faq }
else
format.html { render :new }
format.json { render json: @faq.errors, status: :unprocessable_entity }
end
end
end
def update
@faq = Faq.find params[:id]
@faq.usuario_id = current_usuario.id
respond_to do |format|
if @faq.update(faq_params)
format.html {redirect_to administrator_faq_path(@faq), notice: 'La pregunta fue modificada exitosamente' }
format.json { render :show, status: :ok, location: @faq }
else
format.html { render :edit }
format.json { render json: @faq.errors, status: :unprocessable_entity }
end
end
end
def destroy
@faq = Faq.find params[:id]
@faq.destroy
respond_to do |format|
format.html { redirect_to administrator_faqs_path(@faq), notice: 'La pregunta fue eliminada exitosamente.' }
format.json { head :no_content }
end
end
private
def set_faq
@faq = Faq.find(params[:id])
end
def faq_params
params.require(:faq).permit(:pregunta, :respuesta)
end
end
STACK COMPLETO DEL ERROR:
ArgumentError – wrong number of arguments (given 1, expected 0):
actionpack (4.2.1) lib/action_controller/metal.rb:131:ininitialize'
initialize’
actionpack (4.2.1) lib/action_dispatch/routing/url_for.rb:104:in
actionview (4.2.1) lib/action_view/layouts.rb:355:ininitialize'
new’
cancancan (2.0.0) lib/cancan/controller_resource.rb:80:in
cancancan (2.0.0) lib/cancan/controller_resource.rb:80:inbuild_resource'
load_resource_instance’
cancancan (2.0.0) lib/cancan/controller_resource.rb:61:in
cancancan (2.0.0) lib/cancan/controller_resource.rb:35:inload_resource'
load_and_authorize_resource’
cancancan (2.0.0) lib/cancan/controller_resource.rb:28:in
cancancan (2.0.0) lib/cancan/controller_resource.rb:12:inblock in add_before_action'
instance_exec’
activesupport (4.2.1) lib/active_support/callbacks.rb:448:in
activesupport (4.2.1) lib/active_support/callbacks.rb:448:inblock in make_lambda'
block in halting’
activesupport (4.2.1) lib/active_support/callbacks.rb:164:in
activesupport (4.2.1) lib/active_support/callbacks.rb:504:inblock in call'
each’
activesupport (4.2.1) lib/active_support/callbacks.rb:504:in
activesupport (4.2.1) lib/active_support/callbacks.rb:504:incall'
_run_callbacks’
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in_run_process_action_callbacks'
run_callbacks’
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:inprocess_action'
process_action’
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:inblock in process_action'
block in instrument’
activesupport (4.2.1) lib/active_support/notifications.rb:164:in
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
instrument’
activesupport (4.2.1) lib/active_support/notifications.rb:164:in
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:inprocess_action'
process_action’
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:inprocess_action'
process’
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in
actionview (4.2.1) lib/action_view/rendering.rb:30:inprocess'
dispatch’
actionpack (4.2.1) lib/action_controller/metal.rb:196:in
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:indispatch'
block in action’
actionpack (4.2.1) lib/action_controller/metal.rb:237:in
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:indispatch'
serve’
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:inblock in serve'
each’
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:inserve'
call’
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
traced_call’
newrelic_rpm (3.16.1.320) lib/new_relic/rack/agent_hooks.rb:30:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
traced_call’
newrelic_rpm (3.16.1.320) lib/new_relic/rack/browser_monitoring.rb:32:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
traced_call’
newrelic_rpm (3.16.1.320) lib/new_relic/rack/developer_mode.rb:48:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
block in call’
warden (1.2.6) lib/warden/manager.rb:35:in
warden (1.2.6) lib/warden/manager.rb:34:incatch'
call’
warden (1.2.6) lib/warden/manager.rb:34:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
rack (1.6.4) lib/rack/etag.rb:24:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
rack (1.6.4) lib/rack/conditionalget.rb:25:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
rack (1.6.4) lib/rack/head.rb:13:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
context’
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in
rack (1.6.4) lib/rack/session/abstract/id.rb:220:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
activerecord (4.2.1) lib/active_record/query_cache.rb:36:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
activerecord (4.2.1) lib/active_record/migration.rb:378:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
_run_callbacks’
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in_run_call_callbacks'
run_callbacks’
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
better_errors (2.1.1) lib/better_errors/middleware.rb:84:inprotected_app_call'
better_errors_call’
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in
better_errors (2.1.1) lib/better_errors/middleware.rb:57:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
web-console (2.3.0) lib/web_console/middleware.rb:28:inblock in call'
catch’
web-console (2.3.0) lib/web_console/middleware.rb:18:in
web-console (2.3.0) lib/web_console/middleware.rb:18:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
railties (4.2.1) lib/rails/rack/logger.rb:38:incall_app'
block in call’
railties (4.2.1) lib/rails/rack/logger.rb:20:in
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:inblock in tagged'
tagged’
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:intagged'
call’
railties (4.2.1) lib/rails/rack/logger.rb:20:in
quiet_assets (1.1.0) lib/quiet_assets.rb:27:incall_with_quiet_assets'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
rack (1.6.4) lib/rack/methodoverride.rb:22:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
rack (1.6.4) lib/rack/runtime.rb:18:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
rack (1.6.4) lib/rack/lock.rb:17:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
rack (1.6.4) lib/rack/sendfile.rb:113:incall'
call’
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in
railties (4.2.1) lib/rails/engine.rb:518:incall'
call’
railties (4.2.1) lib/rails/application.rb:164:in
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
call’
rack (1.6.4) lib/rack/content_length.rb:15:in
thin (1.7.0) lib/thin/connection.rb:86:inblock in pre_process'
catch’
thin (1.7.0) lib/thin/connection.rb:84:in
thin (1.7.0) lib/thin/connection.rb:84:inpre_process'
process’
thin (1.7.0) lib/thin/connection.rb:53:in
thin (1.7.0) lib/thin/connection.rb:39:inreceive_data'
run_machine’
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in
eventmachine (1.2.0.1) lib/eventmachine.rb:194:inrun'
start’
thin (1.7.0) lib/thin/backends/base.rb:73:in
thin (1.7.0) lib/thin/server.rb:162:instart'
run’
rack (1.6.4) lib/rack/handler/thin.rb:19:in
rack (1.6.4) lib/rack/server.rb:286:instart'
start’
railties (4.2.1) lib/rails/commands/server.rb:80:in
railties (4.2.1) lib/rails/commands/commands_tasks.rb:80:inblock in server'
tap’
railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:in
railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:inserver'
run_command!’
railties (4.2.1) lib/rails/commands/commands_tasks.rb:39:in
railties (4.2.1) lib/rails/commands.rb:17:in<top (required)>'
require’
bin/rails:9:in
bin/rails:9:in<top (required)>'
load’
spring (1.7.2) lib/spring/client/rails.rb:28:in
spring (1.7.2) lib/spring/client/rails.rb:28:incall'
call’
spring (1.7.2) lib/spring/client/command.rb:7:in
spring (1.7.2) lib/spring/client.rb:30:inrun'
‘
spring (1.7.2) bin/spring:49:in
spring (1.7.2) lib/spring/binstub.rb:11:inload'
‘
spring (1.7.2) lib/spring/binstub.rb:11:in
bin/spring:13:inrequire'
‘
bin/spring:13:in
bin/rails:3:inload'
‘
bin/rails:3:in
Según la documentación, la opción class
es usada cuando el modelo a autorizar es distinto al nombre de tu controlador. En tu caso, como el modelo a usar en ese controlador es Faq
, debería quedar como:
class Administrator::FaqsController < ApplicationController
load_and_authorize_resource :class => 'Faq'
Answered by Alter Lagos on December 31, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP