I am trying to use namespaces to declare an api.
My routes.rb contains:
devise_scope :user do
namespace :api do
namespace :v1 do
match 'log_in', :to => 'token_authentications#log_in', :via => "post"
end
end
end
And my *token_authentications_controller.rb* looks like this:
class Api::V1::TokenAuthenticationsController < ApplicationController
...
def log_in
...
end
...
end
When I hit: api/v1/log_in I get:
Routing Error
uninitialized constant Api
So do I need to declare the namespace somewhere?
Rails expects namespaces to follow directory structure, unless I’m mistaken.
Given your class name for your controller,
Api::V1::TokenAuthenticationsController, rails expects it to live inapp/controllers/api/v1/token_authentications_controller.rb.If you just move your controller to the correct folder, I think you should be fine.
You might also want to make sure to actually declare the namespace modules somewhere, like for instance refactoring your controller as such: