问题
Added an export-to-xlsx option with the axlsx and axlsx_rails gems to an existing Rails 4.2.0 app that uses Devise for authentication. Export to xlsx now works properly:
app/controllers/cases_controller.rb:
class CasesController < ApplicationController
def create
⋮
@public_fields = public_fields
respond_to do |format|
⋮
format.xlsx { render :xlsx => "create", :filename => "cases.xlsx" }
end
end
end
app/views/cases/create.xlsx.axlsx:
wb = xlsx_package.workbook
wb.add_worksheet(name: 'Cases') do |sheet|
sheet.add_row @public_fields
@cases.each do |kase|
sheet.add_row( @public_fields.map { |field| kase[field] } )
end
end
However, the previously working authentication stopped working. Accessing the Devise sign_in
or sign_up
routes, either by clicking the links or by navigating to prompts this error:
NoMethodError in Users::SessionsController#new undefined method `call' for ActionController::Responder:Class
Extracted source (around line #203):
(options.delete(:responder) || self.class.responder).call(self, resources, options)
Trace
responders (2.1.0) lib/action_controller/respond_with.rb:203:in `respond_with' devise (3.4.1) app/controllers/devise/sessions_controller.rb:11:in `new' actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action' actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action' activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional' activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks' activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks' activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action' actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action' actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument' activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument' actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action' actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action' activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action' actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process' actionview (4.2.0) lib/action_view/rendering.rb:30:in `process' actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch' actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action' actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call' actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve' actionpack (4.2.0) lib/action_dispatch/routing/mapper.rb:49:in `serve' actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve' actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each' actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve' actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call' warden (1.2.3) lib/warden/manager.rb:35:in `block in call' warden (1.2.3) lib/warden/manager.rb:34:in `catch' warden (1.2.3) lib/warden/manager.rb:34:in `call' rack (1.6.0) lib/rack/etag.rb:24:in `call' rack (1.6.0) lib/rack/conditionalget.rb:25:in `call' rack (1.6.0) lib/rack/head.rb:13:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call' rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context' rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call' activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call' activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call' activerecord (4.2.0) lib/active_record/migration.rb:378:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call' activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks' activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks' activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call' web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:13:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app' railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call' activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged' activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged' activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged' railties (4.2.0) lib/rails/rack/logger.rb:20:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call' rack (1.6.0) lib/rack/methodoverride.rb:22:in `call' rack (1.6.0) lib/rack/runtime.rb:18:in `call' activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' rack (1.6.0) lib/rack/lock.rb:17:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call' rack (1.6.0) lib/rack/sendfile.rb:113:in `call' railties (4.2.0) lib/rails/engine.rb:518:in `call' railties (4.2.0) lib/rails/application.rb:164:in `call' rack (1.6.0) lib/rack/content_length.rb:15:in `call' thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:in `catch' thin (1.5.1) lib/thin/connection.rb:79:in `pre_process' thin (1.5.1) lib/thin/connection.rb:54:in `process' thin (1.5.1) lib/thin/connection.rb:39:in `receive_data' eventmachine (1.0.5) lib/eventmachine.rb:187:in `run_machine' eventmachine (1.0.5) lib/eventmachine.rb:187:in `run' thin (1.5.1) lib/thin/backends/base.rb:63:in `start' thin (1.5.1) lib/thin/server.rb:159:in `start' rack (1.6.0) lib/rack/handler/thin.rb:19:in `run' rack (1.6.0) lib/rack/server.rb:286:in `start' railties (4.2.0) lib/rails/commands/server.rb:80:in `start' railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server' railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `tap' railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server' railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!' railties (4.2.0) lib/rails/commands.rb:17:in `' bin/rails:8:in `require' bin/rails:8:in `' spring (1.3.3) lib/spring/client/rails.rb:27:in `load' spring (1.3.3) lib/spring/client/rails.rb:27:in `call' spring (1.3.3) lib/spring/client/command.rb:7:in `call' spring (1.3.3) lib/spring/client.rb:26:in `run' spring (1.3.3) bin/spring:48:in `' spring (1.3.3) lib/spring/binstub.rb:11:in `load' spring (1.3.3) lib/spring/binstub.rb:11:in `' /Users/collin/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' /Users/collin/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' bin/spring:13:in `' bin/rails:3:in `load' bin/rails:3:in `'
I know that axlsx_rails patches ActionController::Responder
. Has this change broken Devise?
回答1:
Noel (from the comments) was correct: I was using the wrong version of axlsx_rails with rails 4.2. I fixed this and it works perfectly.
来源:https://stackoverflow.com/questions/29461524/devise-authentication-error-with-actioncontrollerresponder-and-axlsx-rails-gem