Serving uncommon assets on Heroku

Introduction

This post is alternatively titled, “Why I will always hate Flash,” and details some issues I had with adding a Flash file to my asset pipeline in production. My first non-tutorial Rails app is live! Well, technically live… Which is the best kind, if you ask me. There’s still a ton to do before it’s completely ready for production, but I’d like to touch on a hiccup I encountered when deploying the app to Heroku. One important part of the URL shortener I’m creating is the ability to automatically copy the URL generated to the user’s clipboard. After researching the matter a bit, I decided on the same method GitHub uses for their site—ZeroClipboard. I wanted to do things cleanly, so I added a flash folder to the asset pipeline. I then made sure to add the flash folder to my asset path: config.assets.paths << Rails.root.join('app', 'assets', 'flash') After following the simple example on their GitHub’s README, I got ZeroClipboard working flawlessly on my local server. All good, right? Then came Heroku. I knew I’d have to configure a bit more to get static assets served with Heroku; their documentation says as much. I took care to add the rails_12factor gem into my Gemfile to make sure all assets were added, but no dice; the ZeroClipboard flash file couldn’t be found when the app started. To troubleshoot, I fired up the Heroku bash console with heroku run bash. I listed all public assets with ls public/assets and … saw ZeroClipboard! Okay, the file was there, time to troubleshoot further. Next, I fired up the Heroku rails console via heroku run rails console. Within the production Rails console, I tried to list the helper path for ZeroClipboard: puts helper.asset_path("ZeroClipboard.swf"). That one gave me nil, so I knew it was an issue within Rails itself and not just a missing asset. Finally, I headed to StackOverflow to see if others had found similar issues. I found a thread where a person had problems with Heroku serving images. Among the solutions, the OP found that a combination of adding the gem rails_12factor (I’d already added it), and making sure config.assets.compile was set to true in production. Such an easy solution, but this proved to be the thing that made loading my Flash file load on Heroku. Hopes that helps anybody in a similar situation!