Ruby on rails 无法使用设计令牌身份验证发出post请求
我似乎无法向我的控制器端点发出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
获取所有使用该用户的用户
通过遵循他们的文档,我可以对用户进行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>)