Rails 3.1: Treating your '.swf' files as assets

January 12, 2012

This post was originally published in the Rambling Labs Blog on January 12, 2012.

This week, I’ve been deploying one of my current Ruby on Rails projects to WebFaction. For what we found, it’s definitely one of the best options out there for shared hosting with Python and Ruby.

The application being deployed happened to contain some static flash content (not my idea of course :P), which so far we had put in the public/ directory and had served with no problems so far, while testing locally and on Heroku. However, when we were testing it out on WebFaction, it kept returning 404 errors.

So, googling for a while, I stumbled into the swf_fu gem. It’s main function is to treat the swf objects as just another asset in the application. So, I added the following line to the Gemfile:

gem 'swf_fu'

Then, I executed bundle install, created a swfs directory on app/assets and moved all my .swf files into that directory. That was it!

The swf_fu gem also offers some cool helper methods to get the .swf files through the swfobject.js library.

Go ahead and try it out! This has saved me some headaches today!

Enjoy! :D