Sometimes we need to render static content in our Ruby on Rails applications. For example, let’s say I have a content management system that lets users upload their own HTML. Once the file is uploaded via FTP they can go into the CMS and create an article based on the uploaded file. The original content is stored in the HTML file on the file system so the user can easily edit it later in their own editor instead of using a WYSIWYG editor. Fortunately with Ruby on Rails this is really easy to do.

Simply call:

render <file>, layout: true

For example:

render file: Rails.public_path.join("templates","home.html"), layout: true # /public/templates/home.html

That's it! Your app will render the html file. If you don't want the layout you can set layout to false. Otherwise set it to true to ensure that the layout gets rendered.