Subdomains with Rails 2.2

I’m pretty new here, but if anybody had ideas on how to go about using
subdomains for accounts within Rails 2.2. I had seen the subdomain-fu
plugin, but it didn’t look like it plays very well with 2.2. Anyone
know of other plugins that might be useful?

The code to configure this is fairly trivial, try something like this
in the controller(s) you need subdomain access.

before_filter :load_account
def load_account
@account = Account.find(:first, :conditions => [“slug = ?”,
request.subdomains.first])
raise ActiveRecord::RecordNotFound unless @account
end

That’s awesome. I put that code into my application.rb file and it
seems to work great!

In addition, I am looking to a couple of other subdomains not attached
to accounts (ie- admin.domain.com). I installed the request_routing
plugin and it seems to work great. It gives me some good options
within the routes.rb file that allow me to direct the root of the
application to different controllers based on the subdomains. Like
this:

map.root :controller => ‘public_home’, :action => ‘index’, :conditions
=> { :subdomain => ‘’ }
map.root :controller => ‘public_home’, :action => ‘index’, :conditions
=> { :subdomain => ‘www’ }
map.root :controller => ‘system’, :action => ‘index’, :conditions =>
{ :subdomain => ‘admin’ }
map.root :controller => ‘account_home’, :action =>
‘index’, :conditions => { :subdomain => /.+/ }

This seems to work great with Rails 2.2.

This was the plugin I used.

http://github.com/veilleperso/request_routing/tree/master

Hi,

Im looking to implement user based subdomains and catch-all routes
into my app. Can subdomain-fu do this? I followed Ryan B.’
railscast on this but he does not go into dynamically added subdomains
and routes. Can any of you point me to some resources for getting
started on this?
Thanks!