Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法使用设计令牌身份验证发出post请求_Ruby On Rails_Devise_Vue.js_Ruby On Rails 5_Axios - Fatal编程技术网

Ruby on rails 无法使用设计令牌身份验证发出post请求

Ruby on rails 无法使用设计令牌身份验证发出post请求,ruby-on-rails,devise,vue.js,ruby-on-rails-5,axios,Ruby On Rails,Devise,Vue.js,Ruby On Rails 5,Axios,我似乎无法向我的控制器端点发出post请求;但是,我可以创建一个用户,并获取所有使用该用户的用户 通过遵循他们的文档,我可以对用户进行CRUD。如果我使用post路由在用户控制器中创建另一个端点,我会得到: 筛选器链暂停为:验证\u用户!渲染或重定向 但是get有效。我的应用程序.rb: config.middleware.insert_before 0, Rack::Cors do allow do origins '*' resource '*', :head

我似乎无法向我的控制器端点发出post请求;但是,我可以创建一个用户,并
获取所有使用该用户的用户

通过遵循他们的文档,我可以对用户进行CRUD。如果我使用
post
路由在用户控制器中创建另一个端点,我会得到:

筛选器链暂停为:验证\u用户!渲染或重定向

但是
get
有效。我的
应用程序.rb

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*',
      :headers => :any,
      :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
      :methods => [:get, :post, :delete, :patch, :options]
  end
end
用户CRUD仅适用于路径端点,而不适用于我的路径端点

# controllers/api/v1/api_controller.rb
module Api::V1
  class ApiController < ApplicationController
    before_action :authenticate_user!
    respond_to :json
  end
end

# controllers/api/v1/users_controller.rb
module Api::V1
  class UsersController < ApiController

    def create
      render json: 'created'
    end

  end
end

# routes
scope module: 'api' do
  namespace :v1 do
    post '/users/test', to: 'users#create'    # not authenticated!
    get '/users/test', to: 'users#create'     # authenticated.. works
    # resources :users, only: [:index, :show] # no issues here
  end
end

原来这就是我用axios发布数据的方式。我应该将数据放在标题之前:

axios.post('url', <data-to-post>, <headers>)
axios.post('url',)
相反,我只发送了
参数
,而没有发送
标题
。问题解决了

axios.post('url', <data-to-post>, <headers>)