Subdomain accessing only specific resources with Rails

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

What happens is the following:

Visiting the domain dominio.com I can not access the API, so far so good.

The problem comes up when visiting api.dominio.com , I just wanted to get access to the users resource that is in the namespace :api and nothing else. But the opposite is true. even using the api.dominio.com subdomain I can access root and other resources outside of it as :posts .

    
asked by anonymous 23.06.2015 / 16:16

0 answers