Rails Subdomains With Authentication

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.

FOR RAILS 2.3:
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:

http://github.com/fortuity/subdomain-authentication

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”.

Advertisements

3 Responses to Rails Subdomains With Authentication

  1. Wayne says:

    Thanks. Great work. I am new to Rails and this was easy to pick up and learn from. I had it up and running on my mac in no time. The tutorial is easy to understand but I am having a hard time integrating with a currently working app.

    Is there any tips you can add for extending the Site model? I keep getting routing errors?

    • Daniel Kehoe says:

      I’m glad it’s helpful. It may be easier to build a new app with the features you require using the example as a base, rather than trying to merge the example with an existing app. Adding functionality to the Site model should be easy. Email me directly if your app is on GitHub and I’ll take a look.

  2. Tinu Cleatus says:

    Hi, Thanks for this great work. However, I’m not able to get subdomains working on development. It just says “Server not found”. 😦

%d bloggers like this: