show one application on 2 site with different front ends but same back end, in ROR hosted on heroku - ruby-on-rails

I have an application in rails and hosted on Heroku. Now , what I want is that the application can be accessed from 2 different domains, when the application is accessed from suppose a.com it should have a specific frontend, and when accessed from b.com it should display some other frontend. The backend should be same for both.
To achieve this I suppose there is only one way I guess, which is to have two different application with same backed code, and same database(I am using PostgreSQL). I need some help on how Do I achieve this, if not, then some other alternative.

You could have only one app for both if it's easier for you. I would then suggest you configure config/routes.rb to respond differently according to the domain name.
See another answer about it here: Rails routing to handle multiple domains on single application
And the Advanced Contraints in Rails here: http://guides.rubyonrails.org/routing.html#advanced-constraints

Related

Different apps for website and control panel?

I'm developing my first useful rails app at the moment and have a general question.
How are bigger applications like digitalocean.com or invisionapp.com set up:
Are the website and control panel always two different applications?
If not, what is the setup to seperate these two in one app on different subdomains, for example with rails?
I hope the question is clear, I wasn't able two find an answer.
Thanks in advance!
Check you this question Rails routing to handle multiple domains on single application
I'm not sure about digital ocean architecture, but I think that they have multiple apps.
At the beginning of learning rails it is not necessary to build website and control panel as different apps.
Let them be a single app, just locate them on different subdomains.
And with help of constrains in routes.rb you can route requests to different controllers, depending on required domain.

A single Rails app hosting multiple domains with caching

I want to build a rails app that will host multiple domains(sites).
Some content will be similar across all the sites which is why I want it in the one database/app. I thought that I could use a different controller for each domain/site with each action relating to a single page ( each site will only have 4-5 pages ).
This seems possible given the answer here, however I'd like to know what effects this would have on caching, using nginx as the server ( As it's mostly static content I'd like to use page caching )
i.e wouldn't the app need to hit at every request to process the right page/domain?
I dont think thats a good solution. You should setup the application n times and handel the domains/subdomains using nginx and the upstream module.
Using one single instance of an application for various domains seems to be a loose solution to me. I would avoid that unless the content of the sites does depend on another directly. And even in that case I think an API is the better solution.

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?
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.
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:
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.
You should register for domain *.myfi.com so that anyone in the world hit with anysubdomain.myfi.com, it comes in your application.
Then from the url part, you should identify the subdomain (customer1) that is being used, and need to set that in session.
Now when someone will try to login, you must verify the account in the context of that subdomain's account.
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.

Hosting multiple sites via rails - Should I use one rails instance, or many?

I am building a rails app that will host multiple archery league websites. Lets call it myarchery.com, and say I have 2 sites: billsleague.myarchery.com and jimsleague.myarchery.com.
Now when I build this I can either:
Have one rails app serve up the subdomains (basecamp style), sharing all models, etc, but putting an account attribute on everything
Set each account up with its own rails app instance
I prefer running them all in one instance - (B/C I can set their sites up immediately when they sign up, have a single login, etc). However, I wanted to see if there legit reason to run them independently.
I plan to run this on a Linode using apache/passenger, if that influences your answer
Using rails3, you get subdomain routing 'for free'. See http://railscasts.com/episodes/221-subdomains-in-rails-3.
I don't see why you'd need an account attribute on everything; your normal associations should allow you to determine ownership of subobjects.
Running multiple instances per subdomain might seem simpler, but you will pay a heavy price in maintenance. It just does not scale well.
I would think that if they are the same site, running one instance is fine, but if you need to brand them differently, you could benefit from splitting the bits that differ and use, say, svn externals to load in the bits that differ, such as assets and layouts.
Either way works fine, having them all in one instance makes it easier to maintain your code.

Ruby on Rails: How to separate the promotional site from the main app?

I am building my first SAAS app and I am new to Ruby on Rails. I want to build the app so that the promotional site (www.myapp.com, the site where the users sign up) and the main app that the users will use (each account will have it's own subdomain) are separate apps so that I don't have to push updates to both when I only want to make changes to the other (also just so I can have a clean separation). The problem is, you can't host one app using wildcard subdomains and another app at a specific subdomain (www). Is there a clean way to separate the two?
I am wondering how other people have done this. Am I going to too much work to separate the two? Is there a way that I can I create some sort of router that routes requests from "reserved subdomains" (www, blog, help, etc) to the promotional app and all other requests to the main app?
I would create a subdomain route for 'www' in your rails app whichs points to a separate rack app(another Rails or Sinatra app etc) which would be your promo site.
Watch these two railscasts, which should give you the ammo to accomplish this.
http://railscasts.com/episodes/221-subdomains-in-rails-3
http://railscasts.com/episodes/222-rack-in-rails-3
Hope this helps.
You said "The problem is, you can't host one app using wildcard subdomains and another app at a specific subdomain (www)"
But you can.
If you have an A record of www, and then a * record pointing to your app, it will work perfectly fine.

Resources