2017-10-21 1 views
0

순수한 html/js로 만든 게임을 위해 Rails API 전용 앱을 만들고 있습니다. 더 나은 구조를 위해 큰 Rails 프로젝트 내에있는 페이지가 있어야합니다 (사용자 등을 추가 할 것입니다). 공공의? 앱? 루트 수준에서 폴더를 만들어야합니까?내 페이지는 어디에서 Rails API 프로젝트에 있어야합니까?

+1

어림짐작은 api 컨트롤러와 뷰를'/ api '에 저장하는 것입니다. 그래서 당신은 app/views/api/[name_of_controller]/[name_of_view]에 뷰를 저장할 수 있습니다. *' –

+0

API 전용 레일즈 애플리케이션이라면 자바 스크립트 클라이언트 코드를 분리 된 저장소에 넣고 클라이언트를 배치 할 것입니다 다른 위치로. – spickermann

답변

1

API 만 제공하려는 경우 여러 가지 방법으로이를 수행 할 수 있습니다.

레일 전용 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}  

Controlers : - 샘플!

#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 
관련 문제