Mark
Mark

Reputation: 823

Running 2 websites off of same Rails codebase?

I am currently developing 2 sites that have identical functionality for a single client, but the client wants to combine the admin in the backend for ease of use. The sites will share a single database, users table, etc.

How can I set up a Rails application so that the domain name is the only flag that determines which site a user is signing up for, as well as what content they see when they're logged in?

Details

I have two photography websites: photosoftrains.com and planephotos.com. The sites will have identical functionality, but completely different visual designs. A site visitor that goes to photosoftrains.com should see the train site (train background, train content, train photos). If they register, they can comment and upload photos of trains to the site. If that same logged-in user goes to planephotos.com, they would have to re-register to interact with the site. Otherwise, they could still browse the site as an unregistered user.

Babysteps

  1. What is the best way to detect the domain name, and redirect the not-logged-in user to the appropriate home page?
  2. How can I set a global variable when the user starts interacting with one of the specific sites, so that browsing or adding content is completely segregated from the other site, but as efficient as possible?

Is this even possible, or should I separate them into two completely different apps that simply share the database?

Upvotes: 0

Views: 748

Answers (3)

Dex
Dex

Reputation: 12749

What I usually do for Admin sections is create a separate namespace (That is, make a separate directory underneath app/controllers) with a subdomain. Essentially the views and controllers are all different, but the models are all the same.

In my routes, file I create some constraints for a subdomain by going:

constraints(:subdomain => /admin/) do
   namespace :admin do
       resources :mymodel # ......
   end
end

You don't want a subdomain, you want a separate domain entirely. You can try this link: Rails routing to handle multiple domains on single application

As far as setting a global variable, you won't need to if you create a separate namespace and route accordingly.

Upvotes: 2

greenLizard
greenLizard

Reputation: 2346

Building two separate application can be a maintenance pain in the future, but on the other hand segregating data for each application can lead to problems in the database level. If you decide to build one app you can create different folders inside the view folder and keep the different views separated. request.url will give you the url. Better speak with the client discussing any future changes that might affect your implementation.

PS. I would go for two separate applications. For me this is the safest way to tackle this scenario. Any future changes and upgrades can be easily made to one of the applications and transferred.

Upvotes: 0

Andreas Lyngstad
Andreas Lyngstad

Reputation: 4927

Make two apps. Deal with merging when it happens.

You can always seed one database into the other later.

Make one app with all model and controller logic. When you start the design work, use git to make two separate branches.

They might have some issues with merging the two sites in the future, because the users might not like that they suddenly have an account on a page they have not sign up on.

In these kind of scenarios I would really discuss the need for two sites. There are many solid arguments for just have one. They probably have their reasons, but for a technical view two different apps is the best way to go.

Rails is "convention over configuration". This scenario will give you an epic battle against rails with a lot of configuration issues. And you do not want to fight rails.

The only advantage of having one app, is the combined admin. But, this will have to have two seperate lists of users (and all the other models you have). So, it will be just as painfull as having two seperate admins

Upvotes: 1

Related Questions