3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

railsで一部pathをサブドメインにする(メモ)

Posted at

実装方法

constraints subdomain: 'hoge'でいける

constraints subdomain: 'hoge' do
	# ...	
end

ローカルで開発をする場合

vi /etc/hostsで設定ファイルを開き、localhost:3000にサブドメインを設定する必要がある

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1 hoge.localhost.local

hostファイルの127.0.0.1の行に自分で設定したいサブドメインを記述
(hoge.localhostだとなぜかうまくいかなかった🤔)

その後hoge.localhost.local:3000でアクセス可能

request specでサブドメインをtestする方法

headerにHOSTを追加すればいける

describe 'GET #hoge' do
  it "responds with status :ok" do
    headers = { "Host" => "hoge.example.com" }
    get hoge_path, headers: headers
    expect(response).to have_http_status(:ok)
  end
end
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?