I’m working on stitching together the rails backend/api with a backbone.js web app I prototyped in isolation. Along the way, I started tinkering with – and quickly relying on – the ‘backbone-in-rails’ gem, which gives you a generator for a skeletal set of files for a backbone.js app within your rails app, and handles the asset pipeline.
I wasn’t sure what the benefit would be at first – I’ve already got a lot of js written, and I’m just integrating it all together. However, after about my second use of it, it really just became clear that it’s a nice time saver, an intuitive part of the rails workflow, and a good tool for keeping your namespacing and file system consistent.
There was a brief moment of hair-pulling, though, so I’m throwing this note out into the hive mind.
The documentation helpfully tells you that the whole thing defaults to coffeescript, but you can give the ‘– javascript’ directive to the installation script and it will support plain old javascript. What it doesn’t make explicit (at least, not explicit enough for dullards like me
is that you’ll also want to give that directive each time you fire off the scaffold script, or you’ll be left with a bunch of .coffee files where you expected plain old .js files.
It’s not the worst thing that can happen – there is a rollback script, and it’s not a huge mess – but since the whole purpose of the gem is to save you from having to go touch half a dozen files to add a new model to your backbone.js app, it’s worth noting.
I know I should make the coffeescript plunge – and I will, someday, probably – but it’s really nice that this little time saver supports the old fashioned way for us old fashioned js hacks.
Cheers!