Tutorial Explanation
This tutorial is a reformatted version that I have taken the time to fix any errors I spotted from the version on the Typo trac site. I cannot guarantee it will work and this remains to be seen if it will. This is a proof of concept and should be tested with a dummy site before you attempt any production level deployments using these methods.
You need a Virtual Host or Server that supports wildcards.
In Apache config file it will look like this:
<VirtualHost *:80>
ServerName rubyonrailsblog.com
ServerAlias *.rubyonrailsblog.com
DocumentRoot /home/typo/public_html/public
ErrorLog /home/typo/log/error_log
CustomLog /home/typo/log/access_log combined
<Directory /home/typo/public_html/public>
Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Customize environments.rb and application.rb
2.1 environments.rb
ActiveRecord::Base.configurations = File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) }
ActiveRecord::Base.establish_connection
....
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:database_manager => CGI::Session::ActiveRecordStore)
Search for this lines and comment these out with a #.
application.rb
before_filter
:selectdb ...
def selectdb
sub = @request.host.split('.').first
ActiveRecord::Base.establish_connection(:adapter => 'mysql', :host => 'localhost', :username => 'root', :password => '', :database => sub)
end
insert this lines in application.rb.
3. create one or more Typo Databases
4. How does it work?
This customization of Typo selects the right database by the first part of the domain
domain | Database |
mp.rubyonrailsblog.com | mp |
blogtwo.rubyonrailsblog.com | blogtwo |
Conclusion of this tutorial
This tutorial remains incomplete. It is a starting point proof of concept. Good luck with this. Please report any feedback or improved methods of doing this. This is simply a beginning concept and remains untested. I rewrote this tutorial from a previous one from the typo trac site that was improperly formatted and corrected any errors I saw so that it was properly formatted.