Nick Ginanto
Nick Ginanto

Reputation: 32170

Organizing Rails files within app folder for api

All setups I've found use the following folder structure

/app
 /controllers
   /api
    /v1
 /views
   /api
    /v1
 /models

This is ok, I guess. But I am trying to get a structure that looks like

 /app
  /api
   /v1
    /controllers
    /views
   /v2
    /controllers
    /views
  /controllers #for non api stuff
  /views #for non api stuff

at the moment, my routes for the api are set as

scope module: :api, defaults: { format: 'json' } do
    namespace :v1 do
    ..
  end
end

with controllers like Api::V1::MyController < ApplicationController

Is there a way to have this kind of structure?

Upvotes: 2

Views: 1210

Answers (1)

djsmentya
djsmentya

Reputation: 315

I think better way is to extract your api to gem.

Upvotes: 0

Related Questions