2
I’m using Rails 4.2.2
I have the following code in the config/Routes.Rb file:
Rails.application.routes.draw do
namespace :api, constraints: { subdomain: 'api' }, path: '/' do
resources :users
end
root "pages#home"
resources :users
resources :posts
end
Here’s what’s going on:
Visiting the domain dominio.com
I can’t access the API, so far so good.
The problem arises when visiting api.dominio.com
, wanted only access to the resource users
which is in the namespace :api
and nothing else. But the opposite happens. even using the subdomain api.dominio.com
i can access root and other resources outside it like the :posts
.
Have it that way
namespace :api, path: '/', constraints: { subdomain: 'api' } do
and place afterresources :posts
(lastly).– Bruno Wego