如何添加' api'在设计路线上

时间:2016-09-11 03:14:54

标签: ruby-on-rails devise

设计路线 routes.rb

devise_for :users

制作如下路线:

         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_session GET    /api/users/sign_in(.:format)       devise/sessions#new
        user_session POST   /api/users/sign_in(.:format)       devise/sessions#create
destroy_user_session DELETE /api/users/sign_out(.:format)      devise/sessions#destroy
       user_password POST   /api/users/password(.:format)      devise/passwords#create
   new_user_password GET    /api/users/password/new(.:format)  devise/passwords#new
  edit_user_password GET    /api/users/password/edit(.:format) devise/passwords#edit

2 个答案:

答案 0 :(得分:1)

我得到了:

    scope path: :api do
      devise_for :users
    end

答案 1 :(得分:0)

你可以尝试

namespace :api do
  devise_for :users
end