Rails Subdomains With Authentication

February 27, 2010

FOR RAILS 3.0: See my Github repo for a complete example implementation of Rails 3 subdomains with authentication (including a detailed tutorial). It’s much easier to implement subdomains in Rails 3 than in Rails 2.3. Still there’s a few tricks to solve some common problems which you can see in the new example.

I’ve released an open source application for Rails 2.3 that shows how to integrate subdomains with authentication.

User management and authentication is implemented using the Devise gem. The subdomain_routes gem implements subdomains and routing.

You can use this project as a starting point for any Rails web application that requires subdomains and authentication. You can easily customize the application for your own needs.

You can obtain the source code here:


A complete walkthrough tutorial is available on the GitHub wiki. The tutorial documents each step I followed to create the application:

View the Tutorial

This application implements a particular scenario where subdomains are required. There is a “main” domain where anyone can visit and create a user account. There is an “admin” subdomain for the exclusive use of administrators. And registered users can create any number of subdomains which could host blogs or other types of sites. This approach is familiar to users of sites such as wordpress.com and can be called “blog-style subdomains in Rails”.

Interaction Design Resources

April 25, 2008

Most web applications are built by teams of software developers and graphic designers. When software developers build their own sites, they tend to reuse designs they’ve used before or borrow from sites they like. Sometimes they’ll ask a graphic designer to create a few icons or propose a fresh look and feel. For their part, graphic designers tend to want to create the kind of eye-catching design that will win design awards for innovation and creativity. In my experience, most developers and designers are only dimly aware that there is a profession called “Interaction Design.” With any profession, there is a body of knowledge and expertise, and in Interaction Design, it’s all devoted to developing the optimal user experience. Most web applications need interaction design. At a minimum, developers and designers would do well to familiarize themselves with the accumulated body of knowledge from the interaction design field. And, if possible, get an interaction design expert on your team.

I’ve begun collecting favorite sources of information about interaction design:

and I’ll add to this list as I find more.

Hosting and Development at Heroku

March 12, 2008

For a well-funded start-up, there’s no web application hosting better than Engine Yard. I’ve used them and the level of support is better than I’ve experienced from any other hosting provider. With Engine Yard you get a team of sysadmins and application programming gurus who are leaders in the Rails community. You’ll pay for it (close to a thousand dollars per month for a staging server and redundant production servers) but it’s a better bargain than any other alternative if you’re rolling out a web app for the world to use.

If you’re not well-funded or ready to go live to the world with your web application, there are a dozen or more web hosting providers that specialize in hosting Rails web apps and will charge you less than $30/month for a virtual server. I’ve used MediaTemple and DreamHost. You get what you pay for and that often includes configuration headaches when you’d rather be coding.

You might prefer a newer approach, from Morph Exchange. They reduce the configuration overhead for deploying a Rails app.

There’s another alternative: Heroku. See the discussion here. James, Adam, and Orion have this crazy idea that you should be able to develop a Rails app and host it with zero configuration. And then use your web browser to edit the code! You sign up for an account and that’s it. Not only can you upload an existing web app and see it run immediately, but you can create a Rails app, or upload and edit an existing app, right in the Firefox web browser. This is an amazing alternative to the conventional model of developing an app locally and deploying it to a remote hosting platform.

The Heroku approach makes a lot of sense when you’re building an app to learn Rails. Or when you are in the early stages of development and need a way to show your collaborators (or potential customers) what you’re working on. Or if you are running any sort of web app that has no revenue stream to support it.

Rails Tutorial Showing RESTful Authentication

February 22, 2008

This tutorial, Restful Authentication with all the bells and whistles, uses Rails 2.0.2 and accommodates user account activation, changing passwords, forgotten passwords, enabling/disabling users, roles and OpenID.

It has advantages over the Caboose Sample rails application because it is accompanied by extensive community discussion, which serves as documentation. It is also more full-featured and up-to-date.

It’s missing any testing (no Test::Unit or rspec). Otherwise, it could be a good starting point for a Rails example app.

UPDATE: Rails has advanced since this discussion was relevant. As of February 2010, Rails is currently at version 2.3.5 (and Rails 3 is in beta). Several Rails gems are now available that provide a turnkey authentication solution, including Authlogic, Devise, and Clearance. You can also look at Technoweenie’s restful-authentication generator. The Ruby Toolbox page for Rails Authentication shows which are most popular. I personally recommend Devise and the Devise Example Application.