how to handle devise's authenticate_user! with ajax call?

后端 未结 2 497
遥遥无期
遥遥无期 2021-01-05 04:40

I have a form with :remote => true which means it will be submitted through ajax.

In the controller, I have such code:

before_filter: authenticate_us         


        
相关标签:
2条回答
  • 2021-01-05 04:46

    It is quite funny but change in devise.rb http_authenticatable_on_xhr to false

    config.http_authenticatable_on_xhr = false
    

    did the trick for me... without overriding authenticate_user! method

    note: I also added :js to navigational formats

    config.navigational_formats = [:"*/*", "*/*", :html, :js]
    
    0 讨论(0)
  • 2021-01-05 05:02

    You need do your own authenticate_user! action and in this action you can have the behaviour your want.

    def authenticate_user!
      unless current_user
        render 'my_js'
      end
    end
    
    0 讨论(0)
提交回复
热议问题