ActionController::InvalidAuthenticityToken in RegistrationsController#create

前端 未结 8 1471
后悔当初
后悔当初 2020-11-29 19:39

Hi I am using Devise for my user authentication suddenly my new user registration was not working.

this was error I am getting.

ActionController::In         


        
8条回答
  •  孤独总比滥情好
    2020-11-29 20:35

    Per the comments in the core application_controller.rb, set protect_from_forgery to the following:

    protect_from_forgery with: :null_session
    

    Alternatively, per the docs, simply declaring protect_from_forgery without a :with argument will utilize :null_session by default:

    protect_from_forgery # Same as above
    

    UPDATE:

    This seems to be a documented bug in the behavior of Devise. The author of Devise suggests disabling protect_from_forgery on the particular controller action that's raising this exception:

    # app/controllers/users/registrations_controller.rb
    class RegistrationsController < Devise::RegistrationsController
      skip_before_filter :verify_authenticity_token, :only => :create
    end
    

提交回复
热议问题