About the Author
Carlos Muñiz is a software engineer for Spree Commerce Certified Partner Crowd Interactive. He is always interested in being part of new and innovative projects, looking for new ways of interaction and combining different technologies. Crowd Interactive is a leading Ruby on Rails consultancy that specializes in creating and scaling Rails applications and building high-quality stores for customers who are passionate about the creative process.
In many Spree projects where I’ve worked previously, it had become necessary to handle static pages like “Help,” “Terms and Conditions,” “About Us,” etc. In short, all those “stock pages” and some others that come out of the box with any ecommerce website.
I always recommend my colleagues deliver a simple way to generate the pages. Although I “LOVE” to write all the HTML with my own hands, it’s more efficient to use Rails helpers or some other markup such as HAML.
The point is, as consultants, it’s our duty to deliver a stable, functional, installable and, somewhat recoverable product. To achieve this, the extension Spree Static Content has always worked for me because it’s simple to configure and we can easily generate a task to regenerate all the “core” static pages of our project. It’s especially useful for those cases where someone “accidentally” deletes their content.
As you can see, the rake task is quite simple and consists of the following steps:
1. Delete existing pages:
This is a matter of taste. It’s possible to separate the “default” static pages from any other with some scope if you’re able to find specific pages you want to delete. In my case, I’m destroying all of them.
2. Read the information on pages:
For convenience, I always create a “setup” file separately that contains the necessary information for our pages, such as Title, Slug, and the name of the View that we’ll be using as our static page’s Body.
3. Create an instance of a controller:
This has the purpose of delegating the rendering of the views to the proper object allowing us, as I said before, to use view helpers or another abstraction markup language like HAML.
4. Iterate each page:
For each entry we have in our configuration file, we’re going to generate the body of the page letting our Controller instance the renderee. From there on out we only create the Spree::Page.
Static Content Example config file:
That’s all, we just need to go to a terminal and run:
$ be rake static_content:reload
And… Voilà! we won’t have headaches trying to update, maintain or recover any “static page” we deliver and that somebody had erased “accidentally”.
To view this guide in its original format, visit the blog of Crowd Interactive.