What are the pros/cons and considerations that should be taken in separating your mostly static front facing website from your web app in rails?
I am in the process of building a rails app and I am unsure if I need to separate my front facing mostly static website from my web application. I see lots of example of sites having there front facing sites at www.mysite.com while their web apps are at app.mysite.com.
What considerations should I make in this decisions and what are the pros/cons?
Howdy. You can have your static marketing pages in the same app if you like. The way I have done it is have routing constraints. IE
class MarketingSite
def self.matches?(request)
request.subdomain.blank? || request.subdomain == "www"
end
end
class App
def self.matches?(request)
request.subdomain.present? && request.subdomain == "app"
end
end
Rails.application.routes.draw do
constraints(MarketingSite) do
root "static#index"
get "/pricing", to: "static#pricing"
get "/contact", to: "static#contact"
end
constraints(App) do
....routes...
end
end
And then you will have a views/layouts/static.html.erb
which will be used by the static controller like so:
class StaticController < ApplicationController
layout "static"
end
Most of the time websites do this so they can have a completely different application serve their landing pages vs their actual app. For instance you may want to have your landing pages be served by Wordpress, Squarespace or perhaps a static site generator like Jekyll.
Often this is done because separate teams do marketing vs product development, or because it isn't a good use of the product team's time to build and maintain a CMS in the same codebase as the application.
In this case you can just set your root DNS record to point to your website (e.g. wordpress), and another DNS record for app.domain.com to point to your rails app.
There's no need to follow this pattern in your routes if you're doing everything in your rails app just because you see other apps doing it.