Dropping public static pages into the Rails public assets folder

Is it a good idea to drop public static pages into the Rails public assets folder?
Dropping public static pages into the Rails public assets folder
In: Ruby on Rails

You have a new Rails app. You've got a couple of resources down. You've deployed your app. Maybe you have an admin space where you can manage your resources manually. Maybe you have a user space, hell maybe even a user login! Or not. Anyway, you are ready to show it to real people and maybe ask them to use it.

You need a landing page. Wow, and you have a beautifully designed page lying around already in your archives:

<!-- /public/landing-page.html -->
<!DOCTYPE html>  
<html lang="en">  
  <meta charset="UTF-8">  
  <title>Beautiful Landing</title>  
    Nothing better than this nice page! 🎉  

Why not just use this one?

The simplest brute force thing to do would be, to just put a homepage into your app's /public folder. You will notice that there already are some beautiful error pages designed by the Rails team to get you started quickly. Now, all that's left TODO is to point your root, or whatever route, to it:

# routes.rb
Rails.application.routes.draw do 
  # ... here you have nicely followed Rails conventions and added a lot of 
  # resources :your_resource
  # and the like... 👍

  # So now we are abandoning the good old Rails style 😟  
  # root "latest_challenges#index"
  # In favor of some nasty redirect...
  get "/", to: redirect("/landing-page.html")  

There might be a nicer way of doing this than the redirect, but this is all I was capable of at that point in time. At least it works:


This approach has a couple of BIG drawbacks:

  • the page is fairly static and agnostic to resources, so you won't be able to display your resources dynamically in there or use view helpers or similar nice Rails functionality
  • the page is agnostic to layouts, you also can't use partials and the like...
  • it's absolutely NOT the Rails way of doing it (I don't think you will find anything like that in the Rails guides or docs... at least I haven't)

So, if you have some nice HTML files lying around which you want to drop in there real quick and you don't care about showing anything from your database at all, it might be a good choice.

Usually, you won't have this beautiful piece of HTML. Often, you'll rather have some resources to show off to your potential users and make your stuff palatable to them which I'll show in the next articles about that topic.

More from RichStone Input Output
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to RichStone Input Output.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.