Home > Back-end >  Handle ActionController::UnknownFormat in Devise::SessionsController#new error when try to login wit
Handle ActionController::UnknownFormat in Devise::SessionsController#new error when try to login wit

Time:08-14

I'm new in rails and I facing this problem:

After invite a new member the system generates an invitation link. This link invites to the new member to create an account, once the account is created the new member needs to confirm its email but if the member tries to login without confirm its email, it gets:

ActionController::UnknownFormat in Devise::SessionsController#new Extracted source (around line #215):

    (options.delete(:responder) || self.class.responder).call(self, resources, options)
      else
        raise ActionController::UnknownFormat
      end
    end

I tried several solutions like:

  • Adding respond_to :json, :html to the ApplicationController.rb

  • Or Replace: form_for(resource, as: resource_name, url: user_registration_path(resource_name))

with:

form_for(resource, as: resource_name, url: user_registration_path) in views/devise/sessions/new.html.rb.

No luck. Some help here will be very appreciated.

Thank you very much in advance. J.

CodePudding user response:

Thank you very much for your answer @Chiperific, I'm copying the logs here after the sign-in because it is too long for the comments:

10:01:09 web.1     | Started POST "/users/sign_in" for 127.0.0.1 at 2022-08-13 10:01:09  0200
10:01:09 web.1     | Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.
10:01:09 web.1     |
10:01:09 web.1     | redis.pipelined do
10:01:09 web.1     |   redis.get("key")
10:01:09 web.1     | end
10:01:09 web.1     |
10:01:09 web.1     | should be replaced by
10:01:09 web.1     |
10:01:09 web.1     | redis.pipelined do |pipeline|
10:01:09 web.1     |   pipeline.get("key")
10:01:09 web.1     | end
10:01:09 web.1     |
10:01:09 web.1     | (called from /home/julio/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/flipper-redis-0.23.1/lib/flipper/adapters/redis.rb:133:in `docs_for'}
10:01:09 web.1     | Processing by Devise::SessionsController#create as JS
10:01:09 web.1     |   Parameters: {"authenticity_token"=>"v3QNvlX3kS9rYuQvijSzzl64EWnADRxjUicS181rQIAqeD/cX/Mmk5 VTc/RqZXuL/cMK8zzn8Xdrb/v0BBgtg==", "user"=>{"email"=>"[FILTERED]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log In"}
10:01:09 web.1     |   User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "benavides [email protected]"], ["LIMIT", 1]]
10:01:09 web.1     |   ↳ app/controllers/concerns/set_current_request_details.rb:15:in `set_request_details'
10:01:10 web.1     | Completed 401 Unauthorized in 165ms (ActiveRecord: 1.0ms | Allocations: 3959)
10:01:10 web.1     |
10:01:10 web.1     |
10:01:10 web.1     | Started GET "/users/sign_in.js" for 127.0.0.1 at 2022-08-13 10:01:10  0200
10:01:10 web.1     | Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.
10:01:10 web.1     |
10:01:10 web.1     | redis.pipelined do
10:01:10 web.1     |   redis.get("key")
10:01:10 web.1     | end
10:01:10 web.1     |
10:01:10 web.1     | should be replaced by
10:01:10 web.1     |
10:01:10 web.1     | redis.pipelined do |pipeline|
10:01:10 web.1     |   pipeline.get("key")
10:01:10 web.1     | end
10:01:10 web.1     |
10:01:10 web.1     | (called from /home/julio/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/flipper-redis-0.23.1/lib/flipper/adapters/redis.rb:133:in `docs_for'}
10:01:10 web.1     | Processing by Devise::SessionsController#new as JS
10:01:10 web.1     | Completed 406 Not Acceptable in 3ms (ActiveRecord: 0.0ms | Allocations: 1899)
10:01:10 web.1     |
10:01:10 web.1     |
10:01:10 web.1     |
10:01:10 web.1     | ActionController::UnknownFormat (ActionController::UnknownFormat):
10:01:10 web.1     |
10:01:10 web.1     | responders (3.0.1) lib/action_controller/respond_with.rb:215:in `respond_with'
10:01:10 web.1     | devise (e16d60d0fedc) app/controllers/devise/sessions_controller.rb:14:in `new'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/abstract_controller/base.rb:195:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/callbacks.rb:112:in `block in run_callbacks'
10:01:10 web.1     | rorvswild (1.5.13) lib/rorvswild/plugin/action_controller.rb:28:in `around_action'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/callbacks.rb:121:in `instance_exec'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/callbacks.rb:121:in `block in run_callbacks'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/callbacks.rb:139:in `run_callbacks'
10:01:10 web.1     | actionpack (6.0.4.6) lib/abstract_controller/callbacks.rb:41:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/rescue.rb:22:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/notifications.rb:180:in `block in instrument'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/notifications.rb:180:in `instrument'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
10:01:10 web.1     | activerecord (6.0.4.6) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
10:01:10 web.1     | actionpack (6.0.4.6) lib/abstract_controller/base.rb:136:in `process'
10:01:10 web.1     | actionview (6.0.4.6) lib/action_view/rendering.rb:39:in `process'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal.rb:190:in `dispatch'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_controller/metal.rb:254:in `dispatch'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/routing/route_set.rb:33:in `serve'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/routing/mapper.rb:48:in `serve'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/journey/router.rb:49:in `block in serve'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/journey/router.rb:32:in `each'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/journey/router.rb:32:in `serve'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/routing/route_set.rb:834:in `call'
10:01:10 web.1     | turnout (2.5.0) lib/rack/turnout.rb:25:in `call'
10:01:10 web.1     | flipper (0.23.1) lib/flipper/middleware/memoizer.rb:77:in `memoized_call'
10:01:10 web.1     | flipper (0.23.1) lib/flipper/middleware/memoizer.rb:42:in `call'
10:01:10 web.1     | bullet (7.0.1) lib/bullet/rack.rb:15:in `call'
10:01:10 web.1     | warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
10:01:10 web.1     | warden (1.2.9) lib/warden/manager.rb:34:in `catch'
10:01:10 web.1     | warden (1.2.9) lib/warden/manager.rb:34:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/etag.rb:27:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/head.rb:12:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
10:01:10 web.1     | rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/cookies.rb:654:in `call'
10:01:10 web.1     | activerecord (6.0.4.6) lib/active_record/migration.rb:567:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/callbacks.rb:101:in `run_callbacks'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
10:01:10 web.1     | web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
10:01:10 web.1     | web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
10:01:10 web.1     | web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
10:01:10 web.1     | web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'10:01:10 web.1     | turbolinks_render (0.9.21) lib/turbolinks_render/middleware.rb:81:in `call'
10:01:10 web.1     | railties (6.0.4.6) lib/rails/rack/logger.rb:37:in `call_app'
10:01:10 web.1     | railties (6.0.4.6) lib/rails/rack/logger.rb:26:in `block in call'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:80:in `block in tagged'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:28:in `tagged'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:80:in `tagged'
10:01:10 web.1     | railties (6.0.4.6) lib/rails/rack/logger.rb:26:in `call'
10:01:10 web.1     | sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
10:01:10 web.1     | request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/request_id.rb:27:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/method_override.rb:24:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/runtime.rb:22:in `call'
10:01:10 web.1     | activesupport (6.0.4.6) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/static.rb:126:in `call'
10:01:10 web.1     | rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
10:01:10 web.1     | actionpack (6.0.4.6) lib/action_dispatch/middleware/host_authorization.rb:97:in `call'
10:01:10 web.1     | rorvswild (1.5.13) lib/rorvswild/plugin/middleware.rb:20:in `call'
10:01:10 web.1     | honeybadger (4.10.0) lib/honeybadger/rack/error_notifier.rb:33:in `block in call'
10:01:10 web.1     | honeybadger (4.10.0) lib/honeybadger/agent.rb:426:in `with_rack_env'
10:01:10 web.1     | honeybadger (4.10.0) lib/honeybadger/rack/error_notifier.rb:30:in `call'
10:01:10 web.1     | honeybadger (4.10.0) lib/honeybadger/rack/user_feedback.rb:31:in `call'
10:01:10 web.1     | honeybadger (4.10.0) lib/honeybadger/rack/user_informer.rb:21:in `call'
10:01:10 web.1     | webpacker (5.4.3) lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
10:01:10 web.1     | rack-proxy (0.7.2) lib/rack/proxy.rb:67:in `call'
10:01:10 web.1     | railties (6.0.4.6) lib/rails/engine.rb:527:in `call'
10:01:10 web.1     | puma (4.3.11) lib/puma/configuration.rb:228:in `call'
10:01:10 web.1     | puma (4.3.11) lib/puma/server.rb:718:in `handle_request'
10:01:10 web.1     | puma (4.3.11) lib/puma/server.rb:472:in `process_client'
10:01:10 web.1     | puma (4.3.11) lib/puma/server.rb:328:in `block in run'
10:01:10 web.1     | puma (4.3.11) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

CodePudding user response:

ApplicationController doesn't need additional respond_to blocks, your problem is coming from Devise::SessionsController#new, which is inside the gem by default, unless you have already generated it for yourself, which you probably should do in this case.

Also, checking Devise on Github, Devise::SessionsController#new doesn't have a line 215 or contain the code you showed above.

Which means:

  1. The problem is actually coming from somewhere deeper in the stack

show us more of the logs, try to get a full stack trace, give us an example of the link being generated in the email, what is the path that link is trying to hit? What are the variables included in that path?

  1. Email confirmation falls to Devise::Confirmable

So the issue is actually in how you set up Devise::Confirmable. Be sure to look for wikis about this specific feature. Like this one: https://github.com/heartcombo/devise/wiki/How-To:-Add-:confirmable-to-Users

I would also try generating the SessionsController, then adding a debugger right at the top of the #new method and stepping through line by line to see where the error actually develops.

UPDATE

I think something in controllers/concerns/set_current_request_details.rb is morphing your sign in request from HTML to JS.

As indicated by your comment:

this is the invitation link with a token: lvh.me:5000/users/sign_up?invite=mHQFJ65qcgtcGNPfzNBd1DX6 This is the link previous the fail when user tries to login instead of create an account: lvh.me:5000/users/sign_in And this is the link after the fail: lvh.me:5000/users/sign_in.js

And Devise::SessionsController#new doesn't know how to respond to JS.

  • Related