jirikolarik
jirikolarik

Reputation: 1267

Multisite application in Rails (like shopify.com)

I would like create web app like shopify.com. User can pickup subdomain(or domain), theme and have own store.

How can I do this? Create main application, deploy it automatically like new standalone version and update it via git?

I'm using Rails 3. Thanks for your advice.


Based on replies: When I choose to use only one application (without multiple instances) and give user his subdomain, it will looks like their own website. But everything will be in one database (It's good idea?). And how can I have multiple themes in Rails app?

Upvotes: 1

Views: 2800

Answers (2)

Samiron
Samiron

Reputation: 5317

So far I have understood, you want to let your users have their own subdomain, different theme but the functionality would be same right. Users just need to have a feel of something of their own.

Well definitely, you need to have a single application that supports multiple subdomains. A quick googling gave me [ http://37signals.com/svn/posts/1512-how-to-do-basecamp-style-subdomains-in-rails ]. May be you can get some insights from here.

For example if your service is http://www.myfi.com, a brief idea can be:

  1. When a customer is registering, you should let him choose his subdomain. And the newly created account will be associated with this subdomain with a url. Say, http://customer1.myfi.com.
  2. You should register for domain *.myfi.com so that anyone in the world hit with anysubdomain.myfi.com, it comes in your application.
  3. Then from the url part, you should identify the subdomain (customer1) that is being used, and need to set that in session.
  4. Now when someone will try to login, you must verify the account in the context of that subdomain's account.
  5. In fact, all following actions need to be handled in the context of the subdomain's account.

Just tried the gather a glimpse of the implementation here. If you have confusion about something specific, share that also.


Edit:

Whenever you are thinking about multiple theme, you must have simple design which is completely driven by css and js. The app/view files should contain only content and HTML nodes with class names or ids.

Generally a UI designer can put more helpful ideas about how to make such theming mechanism. But all I can feel is, based on the chosen theme by customer, you have to load different css and js.

Actually the strategies can be indefinitely sophisticated and scalable, but its always wise to start with something easy. Then ideas will automatically evolve into better ones.

Upvotes: 1

alexsanford1
alexsanford1

Reputation: 3727

Take a look at LocomotiveCMS, specifically the routing system. Locomotive actually hosts multiple sites inside a single rails application. It does this by inspecting the request URL when it comes in and setting the current_site variable with the site which is set up to handle the domain. Then the current_site is actually just an object which contains all the pages, contents, settings, etc. for the specific site being served up.

So to answer your question, I think a good solution is to give your rails app the ability to serve up multiple sites based on the domain. It's not that hard, and it seems less fragile to me than trying to automatically deploy new instances of an app.

Upvotes: 6

Related Questions