使用设计从Applicationcontroller制作一个单独的Apicontroller

时间:2016-06-23 17:11:17

标签: ruby-on-rails ruby-on-rails-4 model-view-controller devise rails-routing

我正在尝试为网络应用和api单独ApplicationController。我能够成功创建单独的Api::ApplicationControllerApplicationController。问题是我无法通过Api :: ApplicationController获取设计路线以下是我的路线:

devise_for :users
namespace :api do
  mount_devise_token_auth_for 'ApiUser', at: :auth, controllers: {
    token_validations:  'api/token_validations',
    sessions:           'api/sessions',
    registrations:      'api/registrations',
    confirmations:      'api/confirmations'
  }
  get 'boston_api', to: 'cities#boston'
end

这是rake路线的结果:

                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
        cancel_user_registration GET    /users/cancel(.:format)                devise/registrations#cancel
               user_registration POST   /users(.:format)                       devise/registrations#create
           new_user_registration GET    /users/sign_up(.:format)               devise/registrations#new
          edit_user_registration GET    /users/edit(.:format)                  devise/registrations#edit
                                 PATCH  /users(.:format)                       devise/registrations#update
                                 PUT    /users(.:format)                       devise/registrations#update
                                 DELETE /users(.:format)                       devise/registrations#destroy
        new_api_api_user_session GET    /api/auth/sign_in(.:format)            api/sessions#new
            api_api_user_session POST   /api/auth/sign_in(.:format)            api/sessions#create
    destroy_api_api_user_session DELETE /api/auth/sign_out(.:format)           api/sessions#destroy
           api_api_user_password POST   /api/auth/password(.:format)           devise_token_auth/passwords#create
       new_api_api_user_password GET    /api/auth/password/new(.:format)       devise_token_auth/passwords#new
      edit_api_api_user_password GET    /api/auth/password/edit(.:format)      devise_token_auth/passwords#edit
                                 PATCH  /api/auth/password(.:format)           devise_token_auth/passwords#update
                                 PUT    /api/auth/password(.:format)           devise_token_auth/passwords#update
cancel_api_api_user_registration GET    /api/auth/cancel(.:format)             api/registrations#cancel
       api_api_user_registration POST   /api/auth(.:format)                    api/registrations#create
   new_api_api_user_registration GET    /api/auth/sign_up(.:format)            api/registrations#new
  edit_api_api_user_registration GET    /api/auth/edit(.:format)               api/registrations#edit
                                 PATCH  /api/auth(.:format)                    api/registrations#update
                                 PUT    /api/auth(.:format)                    api/registrations#update
                                 DELETE /api/auth(.:format)                    api/registrations#destroy
         api_auth_validate_token GET    /api/auth/validate_token(.:format)     api/token_validations#validate_token
                api_auth_failure GET    /api/auth/failure(.:format)            devise_token_auth/omniauth_callbacks#omniauth_failure
                                 GET    /api/auth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#omniauth_success
                                 GET    /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
                omniauth_failure GET    /omniauth/failure(.:format)            devise_token_auth/omniauth_callbacks#omniauth_failure
                                 GET    /api/auth/:provider(.:format)          redirect(301)
                  api_boston_api GET    /api/boston_api(.:format)              api/cities#boston

路线对我来说很好,但由于某种原因,api请求仍然通过常规ApplicationController。我该如何解决这个问题?

0 个答案:

没有答案