Coding Adventures

SolidusConf 2017

I am very proud to say that I was a chosen speaker at this year’s SolidusConf.  Solidus is an open-source eCommerce platform written in Rails. We use it at and contribute actively to the project. Below is a transcript of the talk as well as my slides. They say the video will be released soon and when it does I’ll post it here. I think the transcript will read better than I presented it so start there. Before we get to all of that I would like to thank my wife for all of her love and support, Greg Price for the topic idea, and Ashton Herrmann for editing and proof reading. They really made this thing come together and without them it wouldn’t have been nearly this good.

Link to Talk

Link to Slides

Keep your store fresh with an API-based CMS


Hello. I’m incredibly happy to be here and excited to tell you about API-based CMSes for your stores. We’ve seen incredible improvements to our sales, advertising potential, and quality of life from these changes.

My name is Eric Saupe. I work for Deseret Book, a book publisher focused on selling Christian and Latter-day Saint products and founded in 1866. We have over 20,000 salable variants including digital products like ebooks and audiobooks. Those products are sold in our 45 retails stores and authorized reseller locations as well as online. We have an e-reader app called Deseret Bookshelf for iOS and Android, and we just launched a subscription service for unlimited access to our audiobooks and over a thousand ebooks. All purchases for Deseret Bookshelf happen through our Solidus-based, and our online orders for physical products are fulfilled through our own warehouse, which runs on Oracle and Logpro.  Our physical products include books, art and home, jewelry, and clothing. Hopefully that gives you a small glimpse into the breadth of products we sell and services we have to communicate with through our Solidus store.


Let’s talk about our road to API-based CMSes. In the beginning was a totally custom Rails app without any sort of open-source e-commerce gem installed. Our marketing team has a really long tail of products to choose from, but unfortunately, the home page was really the only place we had marketing options available. Every time they had new product to advertise, they would send us, the developers, the requested changes: new images, new copy, etc., and we would plan that into our sprint and spend developer time to update the homepage and release for QA before finally deploying to production.

The other trick was scheduling deploys. Since they would often be advertising sales on the homepage, we would need to make sure a developer was ready to deploy at midnight to ensure the sale turned on and off properly.

I’m sure a lot of you have experiences that are probably pretty similar to that. Back then, whenever there were storewide sales, we would create a Category of productsa category is what we would now refer to as a Taxonand place all of their Sale Products in there so they could link to that in their emails. I actually like that approach, but you can see how time consuming all of this would be.

On our homepage there was a Top Ten list that was somewhat automated albeit misleading to the consumer. It took all products sold in the last two weeks and figured out which ones gave us the most revenue. So it really wasn’t the most “popular” since we could have sold a single $2,000 painting and 600 $3 bookmarks and the single painting would be more “popular” to the end user.

It wasn’t all static though; we did use Adobe Target to selectively inject some neat things to users but only in a couple of places. At the top of the page under the navigation we could add messages to the user about sales or site updates. That was more or less all we had as far as tools go for the marketing team. Everything else was done by hand by either the marketing team with their Category pages or with the help of the developers manually updating the homepage.


As grew it became apparent that our custom Rails app was just way too hard to maintain with the number of requests for features and bugs that were coming in. That’s when we started looking at open-source solutions and found Spree. It sounded like a great deal: we take advantage of open source software to help us maintain the e-commerce platform of the site while we figure out how to make it communicate with our warehouse and e-reader API. Simple enough. As part of this upgrade, we were going to give more tools to the marketers to control more of the site. We wanted them to be successful in their jobs, selling all of the different products we offer.

With that we let Adobe Target control all sections of the homepage. Images, text, and links were all given to Adobe Target to allow marketers to update whatever they like. This was pretty good in theory, but it had a lot of negatives in practice. For one, if Adobe Target was down, the homepage was empty. Also, many ad-blocking plugins blocked Adobe Target data entirely because it was requested from the client rather than the server. Our client base is not really likely to use ad-blockers, but as developers and for our more tech-savvy users, the homepage was basically blank. There was no default content served from the site itself; it all relied on Adobe Target.

This gave us a few ideas to improve and iterate on, though. It allowed for A/B testing, which led us to find that a curated Top Ten list outperformed the existing automated one. The marketing team also loved having more control over when homepage updates were released rather than relying on our busy schedules to squeeze in development and deploy times. But the flaws of Adobe Target were too much, and it was clear we needed to phase it out at the end of our contract.

What Then?

With Adobe Target on its way out the door we had a chance to reflect on what it was the marketing team really needed. Obviously, they wanted to update the homepage regularly and add content to other parts of the site like during checkout and just under the navigation, and they wanted scheduled releases.

So what were our options at the time? We could build custom tools for them right on top of Spree, but then we would need to maintain the new database tables, bug fixes, and still have deploys for those changes. As developers we wanted something with minimal maintenance that the marketers couldn’t mess up. That may sound harsh, but with Adobe Target they were given the power to drop in entire blocks of Javascript, and if there were errors in that Javascript, the pages would break. That’s when we found headless CMSes like Contentful and

Headless CMS

Let me just quickly define what a headless CMS is so we can all be on the same page. A headless CMS is a content management system (CMS) that isn’t directly tied to your application. You can think of it like the WordPress admin interface except it isn’t directly attached to your site.

A headless CMS gave us the low maintenance backend that we wanted. It maintains the database and the service for you. It provides the GUI for users to update data, and it will integrate with all of your applications because the data is returned as a JSON object. Many of them also have gems to get up and running quickly. Their GUIs are great for non-technical people, giving them WYSIWYG-type editing that they can save and collaborate on before publishing.

Marketers are in charge of publishing, leaving the developers to focus on developing new features and fixing bugs. We didn’t want to store marketing data in our database because that would add unnecessary complexity and maintenance onto our small team. Outsourcing our marketing data management and publishing to an API-based CMS allowed us to focus on growing the business and let the marketers move more quickly without having to wait for developers to start selling product. vs Contentful

There are a number of headless CMS options out there, but we narrowed our options down to and Contentful. Contentful is definitely the larger organization, but Prismic was less expensive and offered scheduled deploys and previewing, which our marketing team really wanted. Ultimately we chose Prismic. The rest of the talk will be focused on how we integrated Prismic into our site, but the same principles can be applied to any headless CMS.

The Approach

During this time we were actually rewriting our site again after switching to Spree. In our zeal to keep our new Spree site functioning like our legacy site, we customized Spree too heavily and ended up running on our own fork of Spree, effectively eliminating the benefit of an open source community. Our team decided the best course of action was to start fresh with a Solidus-based site and pull over only features and code that were absolutely necessary.

This was also a great time to implement a new Prismic marketing change, and so we began talking with the marketing team about exactly what would be useful to them. We came up with a few components they wanted to use around the site like sliders, hero banners, mini banners, carousels, multi-item carousels, and headings. Knowing what kinds of content they wanted to place around the site, we simply needed to constrain those elements in a way that was both predictable for the site and simple to create and update for the Marketers.

To accomplish that, we created Content Schemas in Prismic. These house all of the data about your component, things like name, product ID, display type, etc. I’ll go over an example of one of these components here.

This is the Content Schema for a multi item carousel. First we see that the Component is a Carousel with the tag  “Multi item,” which helps distinguish between two or more types of the same component. Then each item in the Carousel is displayed with data about it: product name, description, custom link, button text, product SKU, and a custom image. Marketers can quickly update information that is specific to this Carousel without changing any data in our storefront. To identify where to place these components, we use Prismic’s tagging system with defined tags to be pulled into specific locations in our store. For example, anything that needs to appear on a specific taxon page is tagged with the taxon slug like “art-and-home/framed”.

Once the schema is set up and a component created, the site needs to pull in that data from Prismic and display it. We do this by making a call to their API and fetching documents related to a tag based on the page we are currently on. For taxon pages, we pull documents tagged with the current taxon’s slug. Now we have a JSON object with documents that should be rendered. Since this is just JSON and not HTML, we create partials to translate the Prismic data into something more meaningful.

This is our partial for carousels on our site. It handles both single-item and multi-item carousels and renders differently based on the type returned from Prismic. Here is where we are ensuring that the way things are rendered is consistent and within our predefined guidelines. However, in order to encourage a pattern of controlled content entry for flexible content presentation, Prismic does not allow for raw HTML. In our case we are going to handle all the HTML rendering based on the fields entered in Prismic.

Custom names, descriptions, and images are rendered from what was input in Prismic, but we also give the option to simply put in a SKU and handle the rendering from within the store. At Deseret Book we rely more heavily on Variant SKUs than anything else, but you could just as easily use the Product or Variant IDs to specify an individual product you wish to market. This makes life easier because custom data is not required, and it allows the site to consistently render the proper link and image.

Now that you have an idea of what an individual component looks like, let’s take a look at our big project of allowing Marketers to update the entire homepage from Prismic. Each section of the homepage is a different document housing many components. We have our top section, which has a hero banner and mini banners; our left section with carousels, single item spotlights, and headers; and our right section with our curated Top Ten list and some single-image components.

The home page looks exactly the same as it did before we implemented Prismic. Because everything is just a partial in Rails, we were able to match our current site without problem, and we also maintain consistency throughout the site since every Prismic component will render the same way on every page. Hero banners on taxon pages look the same as the Hero banner on the home page.


After converting our entire site to Prismic, we actually saw faster load times because Prismic compresses files for us that previously weren’t being compressed properly. Ad blockers no longer stopped portions of our site from rendering because the server was the one making the request for marking data rather than the client. And we can now cache those pages to make rendering even faster, although the one caveat to that is each page still needs to make a call to Prismic to ensure it has the latest version of the site. If their API is down or stalls, it can add loading time. We wrapped our calls to Prismic in a rescue and cached the old Prismic ref. If there is a problem with the call to Prismic, we just load the currently cached version of each page.

We also integrated Prismic into our mobile apps, and it is now the central location for marketing across all of our sites and allows marketers to quickly make updates and changes to our web and mobile apps. This saved a lot of money in possibly getting another solution that focused on just mobile in-app marketing.


To finish up I wanted to do a really quick demo where we will actually edit our site, do a preview of that edit, and publish it so you can all see how that flow looks.

Here in Prismic I’m editing the home page section to change an image. I can save it up here, then we can preview it on the site, live. Once I’m happy with it, we can either schedule a time for it to be published or just publish it right now. In addition to scheduling a time, Prismic allows you to create releases, which lets marketers work on an entire series of changes and lump them into a single event that will all be published together. Last year they used it with great success for the 12 Days of Christmas sales we do. As you change and make edits to documents in Prismic, it will keep track of the differences. You can even fork different items to make changes just like Git.

I’ll publish it now. We’ll go back to and you can see my change is now live.

To help you get started with all of this, I am announcing two gems, one for Prismic and one for Contentful that will plug into Solidus. Included in those gems are starter templates for basic marketing components. We have loved everything about what Prismic has given us, and I really hope you’ll consider using an API-based CMS to enhance your store too. Thank you.

Getting Started with Programming


A friend of mine called me up recently to ask me how to get started with programming. I’ve gotten these requests more and more as the demand for programmers rises. I’m going to compile a list of resources to help anyone get started with what I feel are the basis for what anyone who wants to program will need. This list is by no means comprehensive and while this will get you started you should not feel like you can go from knowing nothing to building the next Facebook simply by following this guide. It will, however, give you a solid foundation with which you can build and grow to the point where you could potentially build something like Facebook or Instagram on your own or working with a small team.

Which Language Should I Learn?

This depends entirely on what you are trying to do. Some people want to make their work life more efficient by writing small programs to automate their daily tasks while others may want to create websites and web applications. For the first I suggest Python. It is easy to pick up for beginners, it forces good code formatting, and it can be extended to do a large amount of things including creating large websites and applications (Instagram runs on Django which is a web framework built on Python). If you really want to write web applications or create interactive websites I would recommend learning Ruby on Rails. I have written web applications in both languages and I am far more effective in Rails thanks to their mantra of “Convention over Configuration”. I’ll be writing a post about why I feel Rails is better than Django later. Pick your language based on your goals and read the online books I have linked below. They will help you set up your computer and teach you how to create very simple programs for you to have a good base of understanding for programming.

Great Starters Guides

Code Editor

You’ll need a program to actually write the code. I personally suggest Sublime Text 3. It is free, light-weight, and can edit any type of programming file. It has a lot of neat extensions and themes so you can customize it to fit your needs.

Learn Git

Once you have picked your language of choice, no matter what it is, you’ll want to learn Git. Git is a tool to help you version your project and files. Versioning is similar to saving but gives you specific moments to return to. Let’s say you are working on a Word document. You start writing a lot, hit save, then you write a bunch more but decide you hate all that and want to return to where it was when you hit save initially. You could hit CTRL+Z a bunch but it would be nicer if you could point to a specific version of the file and say “I want to start from there again.” With Git you can do that. You make commits, marking moments in time, with messages about the changes made. If you ever want to go back you can simply rollback to any previous commit undoing your current changes. This is useful when you have a working program and then start to do some complicated work only to find you have totally screwed up the project. Just roll back to when it was working and start again.


While you can use versioning locally for your small projects you really start to see its true power when you make your software available for others to review and help; this is known as open-source software. Create an account on Github and they will guide you in pushing your local git versioned projects into projects that anyone can see and help you with. Don’t be afraid of others seeing what you might consider “bad code”. The point of doing this is so others can help you learn and progress. When you have a larger project others can write features and submit bug fixes for your code as well. Once you have a firm grasp of whatever language you have chosen you can even write code for other open source projects to help them with their features and bugs.


Everyone should learn a little bit of programming just like everyone learns a little bit of math. Obviously we can go very deep into mathematics and we can do the same with programming but everyone should have a grasp of the basics and have a foundation even if you don’t do it professionally. I hope this guide was useful and let me know if you have any questions or concerns in the comments below.


Rails 5

As has become tradition, a new full version release of Rails is coming just two years after the release of Rails 4. This new version progresses the platform by bumping the underlying minimum Ruby version and adds a slew of neat features to keep Rails feeling fresh and new.

Ruby 2.2.2

Ruby 2.2.2 is required in Rails 5 because Rails 5 will take advantage of the new Symbol Garbage Collection found in Ruby 2.2. There is also rumor of Rails 5 using the Incremental Garbage Collection found in Ruby 2.2. They have decided to use Ruby 2.2.2 since Ruby 2.2 had a major security vulnerability that is patched in 2.2.2. Ruby 2.2.1 PR Ruby 2.2.2 Commit

Rails API

Many Rails developers these days are finding themselves using Javascript Frameworks more and more. Whether DHH likes that or not it’s a fact of life. Before Rails 5 developers turned to the ruby-api gem which helps create a minimalist Rails application specifically for use as an API. This functionality is now going to be wrapped up and packaged with Rails 5 so no need for another gem. Just use the command rails new <application name> --api and Rails will create your new API app all on its own!

Here are a couple of tutorials for you Backbone and Ember users.

Turbolinks 3

Turbolinks has been a part of Rails since Rails 4 but is getting a major update to hopefully make developers happier about using it. Turbolinks has been criticized for having major usability problems but the concept of only loading portions of the DOM that change is a sound idea. Many Javascript Frameworks take advantage of this idea specifically React.js. Turbolinks will fetch the body content of your page without worrying about rerendering the CSS and Javascript. You can opt-in to specify which parts of the page should be changed if you’d like as well. They also added a progress bar by default to help the user see things are happening behind the scenes, but with the increased speed you hopefully won’t need that.

Action Cable

Action Cable is the feature I am most excited about. Simpler web sockets for Rails. Anytime anyone says web sockets to me I cringe a little just because of how complicated they can be to set up. Many have tried to make the problem easier and Action Cable is Rails’ way of giving it a try.

Rake or Rails

The beginner’s dillema, do I use rake db:migrate or rails db:migrate, is it rake test or rails test? Doesn’t matter anymore, it’s all rails. From Rails 5 on the rails command can be used to run rake commands. Simple change but a nice one.

Integration Tests

Rails 5 is beginning a push to deprecate Controller tests all together in favor of Integration tests. As part of that they are deprecating assigns() and assert_template in controller tests. Aaron Patterson has a great keynote from Railsconf where he outlines the speed improvements made to the Rails testing environment and why Integration tests will be the way to go.


I gave this presentation to the SLC.rb user group July 28th, 2015 and here are the slides from that presentation in case anyone is interested.

Rails 5

A lot of other under the hood improvements are expected to be made but I think I covered a lot of the major upcoming features. Let me know if you have any questions or which Rails feature you are most excited about by leaving a comment below.


One of the great strengths of Rails is the ability to create layouts that house various views of content. You create a layout with a basic HTML structure and then simply drop in your new content based on the view you are rendering. One of the simplest layouts is one that just renders the view that takes up the whole page and this is accomplished by the auto generated

The highlighted line is the important one. That <%= yield %> tells Ruby on Rails that whatever view you load just drop it right there. That’s great! Now we have a simple base layout that houses our imports and basic structure and CSS and we simply drop in our own content inside of this.

Let’s say we want to take it a step further. What if we want a left and a right side bar which is unique to each of our views? We just need to change our basic layout a little bit to add those columns and then update our view template code to take advantage of our new structure.

Yield Sections



Following the suggestion of Obie Fernandez and Kevin Faustino in their book The Rails 4 Way, I have placed the two named structures of the layout first. It makes it easy to distinguish what the smaller sections will contain before getting to the meat of the content. Everything that isn’t labeled as content_for will be dropped in that unnamed yield in the layout.

Render Partials

That’s all well and good but what if you don’t want a specific set of sidebar content for every single view. Maybe a shared partial for the right bar will work great. In that case you’ll need to use the render method in your template to generate the template for you. Here is the example from above but using a shared right side bar template.



Render Partials with Variables

You can even pass in variables to your partials. Let’s say our right side bar takes advantage of some user data. We just pass the user variable to the render with a comma and a hash type variable being passed.



Pretty cool, right? I hope this introduction to layouts and partials was helpful. If there are any problems with my examples or if you have any questions please feel free to leave a comment below.


GitHub is great for open source projects and if you haven’t been there to see what’s going on you’re missing out.  They offer free git hosting for all of your open source projects.  Their UI is great for tracking issues, commits, users, updates, and so much more.  But let’s say you want to use all of that great UI on a project you don’t want open source.  That’s when you’ll need to pay GitHub for a few private repositories.  Or maybe you want to create an organization for you and your developers to create private projects and manage larger applications across many repositories.  You’ll need to pay for that too.  Below are the price lists for both personal repositories and for organizations.


Those prices can get pretty steep.  Luckily for you there is an open source solution to GitHub called GitLab.  It runs on Ruby and you can set it up all by yourself by following these GitLab Installation Instructions.  That assumes you have a server ready to serve and work for you.  If you don’t you can quickly set up a great Amazon EC2 instance and install GitLab in one click.  There are a couple of caveats in getting things set up with the EC2.  Once it is installed you’ll log in using the account and the password is contained in your EC2 log.  Once logged in change your password to something other than the auto created one.  You’ll then need to make some changes to your config files.  SSH into your EC2 instance and update the URL contained in ~/apps/gitlab/htdocs/config/gitlab.yml.  Follow the instructions at the top of that file.  Then you’ll need to set up your email service.  To do that follow the instructions here and then restart the services as described at the bottom of that section.  Now you’re all set!  Placing this in a free Amazon instance will give you a server for a year for free and then after will only cost ~$15 per month.  Much cheaper than GitHub and you have complete control to create groups, private repositories, even public repositories!

That’s all there is to it.  I’ve started using it for my personal projects that I want a UI for issue tracking and other users to join me with and not make public.  If you have any great advice for using GitLab feel free to share in the comments below.

Screenshot from 2014-03-27 14:23:55

Recently we started dumping some data from the database into a shared spreadsheet on Google Docs.  With all of this data it would be helpful to visualize it in some way.  After searching the net it seems there isn’t really a good way to create a chart that is dynamic with what data is in the spreadsheet.  What I want is to have my graph update every time a new row is added to the sheet without having to edit the graph directly.  The solution was to write a custom Google Apps Script to do just that.

To add a Google Apps Script to a document open the document and click Tools -> Script editor…  This opens up a page for editing scripts.  If a prompt appears for what type of script you want to do just select Blank.  Now you just need to paste in this code below.

To make this work for you just change the tabName variable to whatever your tab is that you want to use the graph in, change the start row and start column of where your data begins and what column to end reading.  You don’t need to specify an endRow because we will just be reading all of the data until there is no more.  After that you can customize where the graph will be located, how wide it is, and the titles of the axis.

You’ll see that this method will get called anytime the document is edited or opened by someone who can edit.  Viewers who cannot edit will not trigger the event even on open.  That’s all there is to it.  dynamic Google spreadsheet graphs are now just a click away and once you have it set up you’ll never have to touch it again.

If you have any other Google Apps Scripts tips leave them below in the comments.


AngularJS has a ton of built in directives and functions to make your app come alive very quickly.  One thing I noticed it was lacking was a built in on-enter event.  For example, if a user is in an input field when they hit enter I want it to do something, maybe not necessarily submit the form.  Luckily, AngularJS gives you the ability to create your own directives and add them into your app.  Below is a simple directive that you can add to your app that allows you to add ng-enter to elements in your partials.  Pass it a function and watch as you hit enter and that function is executed flawlessly.

That’s it.  Now just add ng-enter="myFunction()" to any element in your partial that detects keystrokes. This has helped me a ton and added a lot of easy functionality to an already great AngularJS system.  If you have any other great directives or AngularJS tips please leave them below in the comments.


Twitter Typeahead.js has been updated and there are a lot of changes.  I’m going to give a an explanation for a few of their examples and explain the key features and changes that they have made.  For those looking to upgrade to this new version it will require a rewrite of your current Typeahead.js methods so please be aware of that.  The biggest changes are outlined in their changelog.

The most important change in 0.10.0 is that typeahead.js was broken up into 2 individual components: Bloodhound and jQuery#typeahead. Bloodhound is an feature-rich suggestion engine. jQuery#typeahead is a jQuery plugin that turns input controls into typeaheads.

Let’s head to the examples.

The most basic of basic.  Here we have a static list of local data.  Bloodhound needs to be initialized with your data and you can see it handles splitting data up by white space with their tokenizers.  This makes things a lot easier because in previous versions you needed to make sure the tokens to be searched through were already split up by white space.  The Bloodhound object is then initialized and the typeahead object is created.  This is a lot more code but it makes the search more robust as we will see with a more advanced example using prefetch and remote data.

Here we see a very similar example to the one above except that we are getting our data from a URL.  The prefetch variable works to get a set of data and cache it locally.  Even if the page is reloaded that data stays with the user’s browser until it expires or is removed.  As the user begins their search it will have that data ready and on hand but if there is no data to be found in the prefetch Typeahead.js has another URL, stored in the remote variable, that it can make a query to and get data back about what the user is searching for.  These two in conjunction work fantastically well for supplying the user with a set of data that has the speed of being static but can be dynamic by querying the URL for more data as the user goes.  Again we initialize the Bloodhound object and add it to the typeahead initialization.  We are again using the Handlebars template rendering engine to make the search results look great so that hasn’t changed.

The changes are drastic but not hard.  This is a major update to Twitter Typeahead.js and because of that there is deprecation.  My other posts are still useful for older versions but may not apply to versions going forward.  I hope this was helpful in getting you up to speed with the latest version of Twitter Typeahead.js.  If you have any questions or comments feel free to leave them below.


If you’ve spent any time looking at the Bootstrap docs you’ll notice their nav bar on the right.  Very slick example of both Scrollspy and Affix.  I have written blog posts about both of these topics in conjunction with each other titled Bootstrap ScrollSpy Pitfalls and Fixes.  In my example I use a very simple styling for my nav using nav-pills.  This works out alright but what if we want to get exactly what Bootstrap is doing?  Well, let’s figure out just how they do it.

They are using very similar code to what I had in the pitfalls and tricks post so I’ll bring that in here.

Now that we have a simple navigation let’s style it to have sub menus not be shown until the item is in view of the user, just like Bootstrap.

We’ve added some sub menu items to a few of the nav elements.  At this point if you were to render the page it would show all of the items in the list regardless of it being a sub menu or not.  We want to change that so we only see specific sub menus when they are active.  To do this we just need to add a little bit of CSS that will trigger the display of the sub menus.  When the menu item is not active the sub menus are hidden.  When the menu item is activated it displays the sub menus below.

That’s all there is to it! No tricky JavaScript required, it’s all CSS.   Now just adjust the padding, change the color, and add sub menus to your heart’s content.  You now have a side nav that looks and acts just like Bootstrap’s does in their docs.