I want to make the API of my Rails app accessible through a subdomain (https://api.domain.com). I have the following routes defined:
constraints :subdomain => 'api' do
namespace :api, defaults: {format: 'json'} do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :posts
end
end
end
This works but results in the following url:
https://api.domain.com/api/posts
I would like it to be:
https://api.domain.com/posts
The API controllers are in app/controllers/api/v1 where they should stay.
I tried mapping the route but without any success. Does somebody know how to fix this?
Change
namespace :api, defaults: {format: 'json'} do
to
namespace :api, path: nil, defaults: {format: 'json'} do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With