I’ve been working on completing Michael Hartl’s killer — and free — rails 3.2 tutorial for a while now. When I learn new concepts I have to write them down so I won’t forget and will have a reference to go back to, if I do. This is one of those posts.
To have elements of your web page appear without having to rewrite the same code in each page, web developers (like me) use includes of some kind to insert common bits of code once and it gets dynamically generated by the server. In rails, this is called a partial. You can put things like a footer with links, a header with nav, or other elements in partials and then include them in your main layout to display that code automatically.
You would create a new file in the app/views/layouts folder and name it with an underscore at the beginning. Like zoy:
and then put your footer html in it. Then all you do is add this to your main application layout:
<%= render 'layouts/footer' %>
It is that simple. Yay rails!