views:

202

answers:

3

I'm noob with Rails.

I would like to create a Rails powered website which can install automatically a Rails application (Redmine) when a user creates an account (create the application, setup user's preferences, configure the database, etc.) Each Rails application will use its own subdomain.

Any idea how to do that?

+1  A: 

you may want to look into using redmine and a plugin like subdomain_fu that will create subdomains for each user, rather then have 100's of rails apps on your server. you'll run out of ram. Maybe I'm reading your question wrong however. if i am my apologies.

pjammer
No, you are right. As long as each other user don`t see other's projects, it's a good solution.
Etienne Savard
and to help them NOT see other projects, you simply write an authorized_user method in application controller or maybe redmine has one already. subdomains, the better way :-)
pjammer
A: 

You could add a model (eg. Account) which maps sub-domains to database connections. When a request comes in you then switch the database connection on-the-fly based on the sub-domain. You could even add a view path so each sub-domain can have its own look and feel.

For example in a before_filter for application controller:

@account ||= Account.find_by_domain(request.host)
render :text => "#{request.host} can not be found" and return false if @account.nil?
ActiveRecord::Base.establish_connection(@account.database_connection)
self.prepend_view_path @account.view_path
Kris
A: 

Look into rails templates - it's a built-in feature that lets you specify a template for app creation. You can get really granular with them -- mine creates bootstrapped users and content. Here's some examples, and Here's mine... I think it's up to date.

You could use your application to generate the template, customized just for the user, then generate their app from that.

You specify a template when you run the rails command: rails appname -m templatefile.rb

Ben