0
我似乎無法向我的控制器端點發出發布請求;但是,我可以創建一個用戶並使用devise_token_auth所有用戶get
。使用設計令牌無法發出請求驗證碼
通過遵循其文檔,我可以CRUD用戶。如果我創建另一個端點,則在用戶控制器中使用post
路由,我將獲得:
過濾器鏈暫停爲:authenticate_user!呈現或重定向
但是get
有效。我application.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工作只有their路徑終點,但不是我的。
# 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
郵差可以post
當我添加標題,但不是從瀏覽器。不知道CORS的問題,但我認爲不是。我試過了新的鐵軌5 api和相同的。 我的js函數看起來像:
axios.post(`${window.apiUrl}/v1/users/test`, { headers: headerData, project: { title: 'help' } })