LoginSignup
7
5

More than 5 years have passed since last update.

ローカルではサブディレクトリ, リモートではサブドメインにするRouting

Last updated at Posted at 2015-01-13

開発環境ではlocalhost:3000/admin, 他の環境ではadmin.example.jpを管理画面にしたい場合。

あんまり無いケースかもしれませんが、以下のようにするとできました。

config/routes.rb
Rails.application.routes.draw do
  admin_routes = Proc.new do
    resources :articles
  end

  if Rails.env.development?
    namespace :admin, &admin_routes
  else
    constraint subdomain: 'admin' do
      namespace :admin, path: nil, &admin_routes
    end
  end
end

Proc.newとかしなくても良い方法がありそうですね。

そもそもlocalhostならadmin.lvh.meを使えば良いと思います。

7
5
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
7
5