Rails: Rendering a File

This past week, I started building out a solo Rails project, and one of my first steps was to create a general layout for my nav bar, footer, and columns, so that I could use a cohesive structure across my site.

Since I wanted the layout to be pretty standard for all pages (and since the nav and footer are static html), I decided to use Rail’s built-in render file method, so that I wouldn’t have to house my bulky html on the application.html.erb file (or within individual pages, if I ever decide not to use them across the whole site.)

Using render is simple. Create a file containing the html to be rendered (check out render partial if you need to render more than just static content) and place it in a folder in the views directory. Then, in application.html.erb (or wherever you’d like to render your code), simply render the file in erb tags, like this:

Check out the Rails docs for more extensive info about rendering partials and templates.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s