我的页面应该位于 Rails API 项目中的什么位置?

Where should my page be located in a Rails API project?

我正在构建一个 Rails API 唯一的应用程序,用于我用纯 html/js 制作的游戏。为了更好的结构,页面应该位于大型 Rails 项目中的什么位置(将添加用户等)。 Public?应用程序?我应该在根级别创建一个文件夹吗?

如果您只想提供一个 API,您可以通过多种方式做到这一点。

Rails 仅 API: Rails API only

因为只有 api 可能对 JWT 身份验证感兴趣:JWT Sample

路线 - 示例!

namespace :api do
    namespace :v1, defaults: { format: :json } do
        resources :orders, only: [:index, :show,:create] do
            member do
                post 'cancel'
                post 'status'
                post 'confirmation'
            end
        end

        # Users
        resources :users, only: [] do
            collection do
                post 'confirm'
                post 'sign_in'
                post 'sign_up'
                post 'email_update'
                put  'update'
            end
        end
    end
end

#output
...
GET  /api/v1/orders(.:format)  api/v1/orders#index {:format=>:json}
POST /api/v1/orders(.:format)                  api/v1/orders#create {:format=>:json}
 GET  /api/v1/orders/:id(.:format)              api/v1/orders#show {:format=>:json}
 POST /api/v1/users/confirm(.:format)           api/v1/users#confirm {:format=>:json}
 POST /api/v1/users/sign_in(.:format)           api/v1/users#sign_in {:format=>:json}     

控制器: - 示例!

#application_controller.rb
class ApplicationController < ActionController::API
end

#api/v1/app_controller.rb
module Api
    class V1::AppController < ApplicationController
       ...    
    end
end

#api/v1/users_controller.rb
module Api
    class V1::UsersController < V1::AppController
      ...
    end
end