Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Set of protected methods that use the subdomain as a way of identifying the current scope

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
README.markdown

Submarine

Submarine was built upon DHH's Account Location plugin. It gives you a set of protected methods that use the subdomain as a way of identifying the current scope. These methods allow you to easily produce URLs that match this style and to get the current subdomain from a request. Submarine includes support for subdomains in a development environment running on localhost.

Localhost Setup (OSX 10.5)

  • Edit /etc/hosts by adding your aliases after the localhost (on the same line):
127.0.0.1     localhost foo.localhost bar.localhost
  • Then you must clear the cached DNS entries:
sudo dscacheutil -flushcache

Instructions

  • Include Submarine in one of your controllers or just once in the application controller:
class ApplicationController 

  • Submarine will generate the following helper methods (using the default settings): user_url, user_host, user_domain. It will also provide you a method to retrieve the current request's subdomain: current_subdomain

  • By default, all helper methods will query @user.login (hi restufl_authentication) when generating the subdomain part. You can set these attributes by overwriting the subdomain_model and subdomain_column methods in your controller after including the module:

class ApplicationController 

  • Doing so will grant you a new set of helper methods, prepending the subdomain_model instead of 'user' (using the example above): account_url, account_host, account_domain

  • If you pass along a string as a parameter to the helper methods, these will use it for the subdomain part of the URL's.

@account.name
=> 'quack'

account_url
=> 'http://quack.domain.com'

account_url('moo')
=> 'http://moo.domain.com'

Examples

You have a domain that hosts several blogs and you wish to shorten their URL from http://www.domain.com/blogs/fooblog/posts to http://fooblog.domain.com/

class ApplicationController 

If you want to link to each of your blogs when the users visit your domain, you can use the helper methods in your views

<div class="sidebar">
    <ul>
    <% @blogs.each do |blog| %>
        <li><%= blog_url(blog.name) %></li>
    <% end %>
    </ul>
</div>

TODO

  • Use method_missing instead of method_alias for the model name based helpers.
  • Helper method tests
  • Add subdomain based routing support

Copyright (c) 2008 Norbauer Inc, released under the MIT license
Written by Jose Fernandez with support from Norbauer Inc.

Something went wrong with that request. Please try again.