Reputation: 3874
I'm building an API in Rails and I'd like for it to be versioned. My routes.rb
file consists of:
Rails.application.routes.draw do
namespace :V1 do
resources :users
end
end
And I have my controller under /app/controllers/V1/users_controller.rb
, which has this content:
module V1
class UsersController < ApplicationController
def index
render json: {message: "This is a test!"}
end
end
end
When I try to run the rails server on the command line I get the following error:
`default_controller_and_action': 'V1/users' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
I've looked at the link the error message gave me, however it seems to be how to specify a controller to use with a resource. Rather than doing that, can Rails not automatically determine it from my directory structure?
Upvotes: 1
Views: 594
Reputation: 2558
try this one:
Rails.application.routes.draw do
namespace :v1 do
resources :users
end
end
Upvotes: 2