This is a basic Rails application built to demonstrate one approach to working with subdomains in a development environment. The application has two models - Account and User. In this example we are using Devise for user authentication and MiniTest for our testing.
Ruby version: 2.2.3
Rails version: 5.0
Assumption: You are using RVM to manage your ruby versions. If you already have Ruby 2.2.3+ installed as well as Rails 5, you can skip the rvm and gem install steps below.
cd ~/path/to/where/your/projects-go/ rvm use 2.2.3@rails5 --create gem install bundler gem install rails git clone firstname.lastname@example.org:hogihung/demo-app.git cd demo-app bundle install rails db:setup rails db:seed
Running the test suite:
bundle exec guard
Start the Rails Server:
Visit the url: localhost:3000.
Now, try to visit the sign in url: localhost:3000/users/sign_in
You most likely will see the error: "The page you were looking for doesn't exist."
In our development environment there are a couple of ways we can handle working with subdomains. For example, there is Pow
But there is an even easier way so long as you have an Internet connection - lvh.me.
Ok, now we will get this working by using LVH. But first, stop the current rails server. Restart the rails server using the following:
rails s -p 3000 -b lvh.me
Now you can test out our example subdomains, for example:
Subdomain User Password ------------------------------------------------- root email@example.com pw demon-strings firstname.lastname@example.org pw
NOTE: This demo is just enough of an application put together to demonstrate using subdomains. It is the first step towards building a multi-tenancy based application. While it is true that you can log in using a subdomain, the sysadmin user can log in to the demons-strings subdomain and the Sarah user can log in to the root domain. In fact you can use just about any subdomain and you will be able to login.
This demo was created as an illustrative example for the blog post: http://ognt.io/posts/pour-some-subdomains-on-me