routes.rb
constraints subdomain: 'api' do
get 'status' => 'status#index'
resources :users
end
rake routes
users GET /users(.:format) users#index {:subdomain=>"api"}
POST /users(.:format) users#create {:subdomain=>"api"}
new_user GET /users/new(.:format) users#new {:subdomain=>"api"}
edit_user GET /users/:id/edit(.:format) users#edit {:subdomain=>"api"}
user GET /users/:id(.:format) users#show {:subdomain=>"api"}
PATCH /users/:id(.:format) users#update {:subdomain=>"api"}
PUT /users/:id(.:format) users#update {:subdomain=>"api"}
DELETE /users/:id(.:format) users#destroy {:subdomain=>"api"}
ちゃんと subdomain => "api"
が追加されています。
users_controller
特殊なことはしていません。
class UsersController < ApplicationController
def index
render :text => 'ok!'
end
end
etc/hostsを開く
こいつにsubdomainを追加しないとダメなんです。
$ vim etc/hosts
etc/hostsに以下のスクリプトを追加
127.0.0.1 api.localhost.local
http://api.localhost.local:3000/usersを叩く
"ok!"