jfernandez / submarine
submarine
PublicSet of protected methods that use the subdomain as a way of identifying the current scope
README
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):
- Then you must clear the cached DNS entries:
Instructions
- Include Submarine in one of your controllers or just once in the application controller:
-
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_modelandsubdomain_columnmethods in your controller after including the module:
-
Doing so will grant you a new set of helper methods, prepending the
subdomain_modelinstead 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.
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/
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
- <strike>Use
method_missinginstead of method_alias for the model name based helpers.</strike> - Helper method tests
- Add subdomain based routing support
Copyright (c) 2008 Norbauer Inc, released under the MIT license<br/> Written by Jose Fernandez with support from Norbauer Inc.