Heroku无法识别rails api路由

时间:2016-10-19 10:54:48

标签: ruby-on-rails api heroku routes

我有一个适用于我当地环境的rails api。我甚至可以使用Postman提出所有请求。但是,当我将应用程序部署到heroku时,我可以从我的Android应用程序中使用端点,我使用heroku日志得到404错误

  

ActionController :: RoutingError(没有路由匹配[POST]“/ v1 / users”)。

但是,当我运行heroku rake路线时,我发现我的路线符合预期。我怎么可能做错了?

运行heroku rake routes

后来自heroku的路由
         Prefix Verb   URI Pattern                    Controller#Action
    new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
        user_session POST   /users/sign_in(.:format)       devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
       user_password POST   /users/password(.:format)      devise/passwords#create
   new_user_password GET    /users/password/new(.:format)  devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                     PATCH  /users/password(.:format)      devise/passwords#update
                     PUT    /users/password(.:format)      devise/passwords#update
        api_v1_users POST   /v1/users(.:format)            api/v1/users#create {:format=>:json, :subdomain=>"api"}
         api_v1_user GET    /v1/users/:id(.:format)        api/v1/users#show {:format=>:json, :subdomain=>"api"}
                     PATCH  /v1/users/:id(.:format)        api/v1/users#update {:format=>:json, :subdomain=>"api"}
                     PUT    /v1/users/:id(.:format)        api/v1/users#update {:format=>:json, :subdomain=>"api"}
                     DELETE /v1/users/:id(.:format)        api/v1/users#destroy {:format=>:json, :subdomain=>"api"}
     api_v1_sessions POST   /v1/sessions(.:format)         api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
      api_v1_session DELETE /v1/sessions/:id(.:format)     api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}`

的routes.rb

Rails.application.routes.draw do
  devise_for :users
  # Api definition
  namespace :api, defaults: { format: :json}, constraints: { subdomain: 'api' }, path: '/'  do
    namespace :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      resources :users, only: [:show, :create, :update, :destroy]
      resources :sessions, only: [:create, :destroy]
    end
  end
end

0 个答案:

没有答案