. .

Categories

Posts

May 2013
M T W T F S S
« Apr    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Subscribe.

New at Rails – asset-packager

I’m working on my first-ever rails project. More accurately, I’m maintaining and modifying someone else’s, which is the best way to learn a new platform, so I can’t really complain, but it’s also one of the more frustrating ways to learn from time to time. I’m going to try to post all the solutions to my frustrations here, though I’m sure I’ll miss some due to time constratints (I have in fact already missed some due to time constraints).

One thing that I ran across had to do with the rake asset packager. This is a convenient rake plugin from Scott Becker that bundles all your javascript and css files (presumably it can handle other types of files as well, but these will be the primary concern in web development) into a single compressed css bzw. javascript file for faster performance.

I found out about this because some JQuery calendars weren’t popping up like they should. Poking around in the Chrome inspector, I found complaints that Cufon was an undefined method. Well, Cufon is a font packager – nothing to do with JQuery’s datepicker – so this meant there was a general problem loading javascript files. Looking through the DOM elements, I found the following interesting line:

src="/javascripts/base_packaged.js?1328723273"

So, that looked mysterious. Looking in the javascripts directory, I found the base_packaged.js file, but it was empty – ergo something had tried, and failed, to create it. Next step – look at the layout file – and fortunately there is only one for this project, so I didn’t have to play the ever-popular “whichunisit” game with layouts in an unfamiliar project. Obvious candidate for offender:

<%= javascript_include_merged :base %>

And that, ladies and gents, was my introduction to the asset-packager. A quick google of that function name found me all I needed to know.

But here’s what I’m posing about. Apparently there’s a process to this: first you run

rake -T

to make sure that the asset-packager tasks are tasks that rake knows about. For me they were. Then you run

rake asset:packager:create_yml

to create the yaml file that defines all the assets you want to package. When I did that, it told me it was way ahead of me – already has it one of those. Ok, then.

Next is:

rake asset:packager:build_all

CHOKE! I get:

No such file or directory - /var/www/app/current/tmp/base_packaged_uncompressed.js

This turned out to be because there wasn’t even a /tmp directory in my project. Which is the real problem, actually – I’m building a testing server for a project that is already deployed and running – deployed via Capistrano. For various reasons mostly due to the dated-ness of the project, it’s probably better to build the new testing server by hand, with the downside that of course a lot of stuff that Capistrano could have taken care of for me I now have to figure out for myself. Like the fact that the rake asset-builder needs a directory called tmp in which to store its temporary build of my globbed javascript file. Well.

Anyway, that’s worked out now, and everything javascripty is working. YAY!

I know this is kind of a n00b post – but then I’m a Rails n00b struggling to get a Rails 2.3/Ruby 1.8 app running in this Rails 3.2/Ruby 1.9 world – and as we all well know, Ruby’s a lot of great things, but one thing it’s not is backward compatible. So it’s an uphill battle when you’re new. Hopefully someone else who’s new can benefit from this – and all the other entries in what is likely to turn into a series.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>