您需要在application_controller.rb中进行以下更改
更改
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end
至
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :null_session end
编辑
更好的方法是跳过特定控制器的身份验证
class Api::V1::UsersController < ApplicationController skip_before_action :verify_authenticity_token respond_to :json # ... end