Rails/Devise - Creating new users via json request

前端 未结 3 1731
心在旅途
心在旅途 2020-12-24 09:34

I would like to do a new user signup via JSON but I get an invalid authenticity token error.

I would like to not turn the forgery check for all controller. Any sugg

3条回答
  •  抹茶落季
    2020-12-24 09:55

    You could buil your own controller that does not derive from a devise controller.

    def UserSignupApiController < ApplicationController
      skip_before_filter :authenticate_user!
      respond_to :json
      def create
        @user = User.create(params[user])
        respond_with(@user)
      end
    end
    

    I think you get the idea. You just instantiate your User just like you would do in Rails console. I do not recommend this kind of practice though

提交回复
热议问题