Forum: Ruby on Rails Subdomains with Rails 2.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Perry D (Guest)
on 2008-12-03 18:19
(Received via mailing list)
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?
Andrew B. (Guest)
on 2008-12-03 19:19
(Received via mailing list)
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
Perry D (Guest)
on 2008-12-04 16:01
(Received via mailing list)
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.
Ram (Guest)
on 2008-12-05 07:56
(Received via mailing list)
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!
Perry D (Guest)
on 2008-12-05 23:44
(Received via mailing list)
This topic is locked and can not be replied to.