How awesome is that? (A public service announcement for using gems, plugins, and otherwise tested code)

Ok, so let's say you have some code from some guys you worked with once, some really really smart guys, and the code is... well, no, the code is awesome. It extends Rails in such a way that you can do all sorts of hitherto unheard-of magical transformations that make your life so much easier, and your code so much easier to read. And to write. And to understand.

OK, now, when you say it extends Rails, you don't actually mean like a patch or anything. And, actually, you don't even mean like a plugin or a gem. But it extends Rails in a really really awesome way.

OK, so what if the code is untested, really...dense, difficult to read, impossible to understand (even if you really really wish you understood it), and reliant on many other files? And so what if the other files the code depends on aren't in a plugin or a gem. Well, technically, some of them are. But some of them aren't! Which is fun! Because then it's not all conventional-like. Just super magical. I mean, who cares?

Because this is awesome. It gets even awesomer, because as you're busy using these magical transformations -- you don't even have to learn how to do things the regular way. You can just awesome it up and go home.

Which is fucking great. Until you decide to upgrade your application into the future, where everyone else has been living for a while. You know, Rails 10.11 -- or something really awesome like that.

And then, wait a minute, all the code breaks.

The app doesn't start. The code is no longer compatible. And worse, it's no longer compatible in a really really obscure way. That you really wish you understood. But you don't.

How awesome is that?

Integrating the MIT / SIMILE timeline with Rails

This is a brief entry on how to populate the MIT / SIMILE timeline with dynamic data culled from a Rails application via a controller action that returns JSON. There is a plenty of existing solid information on the timeline itself, as well as a tutorial on integrating it with Rails and one focused on a simple html implementation. All these sources are clearly written and give basic usage tips. I recommend them and will not duplicate them here.

However, none of the sources demonstrated how to get dynamic data into the timeline via URL (they focused instead on creating the JSON / XML inline in the view via iterating through collections, or having it pre-existing as an external text file), I'm adding that information here in the hopes that someone else building in Rails finds it helpful.

Read the rest of this post »

Multiple File Upload using SWFUpload on Rails. Part II

This part of the tutorial covers getting the files that you select via your swfupload setup to upload into your Rails application. Part I covers the setup: getting the external libraries, markup, and JavaScript all in place. You can find that here. This tutorial assumes you are using attachment_fu. The Flash / Rails principles would be the same if you are using Paperclip, but the syntax for the upload itself would vary. However, since the main sticking point is the fact that Flash doesn't send the session_id to Rails when it posts data, thereby denying Rails access to current_user or a valid session, it is my hope that this article will be helpful regardless of which attachment plugin you are using.

Read the rest of this post »

If you're not pending, flunk.

I've inherited a Rails project from a big design firm. My job is to stabilize it in its new environment, maintain it, and eventually grow and improve it. Today was a bit traumatic: I deleted 47 files from the project. These were unit tests and functional tests that were either completely empty, like so:

class ModelTest < ActiveSupport::TestCase
# crickets
end

Or functionally empty, a result of leaving scaffolding in place, like so:

class OtherModelTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

Forty Seven Files.

The problem here is not only that much of the app is not tested (nor documented by well-written specs), but the presence of the 47 passing test files gives a false sense of security to anyone eyeballing the project before they realize that the coverage is in name only. Certainly there were many (ok, some) files with active tests in them (I'd say I pulled a little more than half the files from the project) but it left me a bit shell-shocked to realize not only how little was covered, but that this cruft had been passed back to the client.

Read the rest of this post »

Acts As Followed

I released my first Rails plugin today. Acts_as_followed allows you to set up "followships" between users and other resources in your domain. It's fairly simple as these things go, but it was an instance where I felt that encapsulating the logic would make this pattern easier to implement across many projects -- and an opportunity to become more familiar with writing a plugin. Naming-wise, acts_as_followship is a little dry; I actually prefer acts_as_celebrity_stalker, but didn't feel like changing all the names. Perhaps in the future.

Read the rest of this post »

Getting Started with Multiple File Upload using SWFUpload on Rails. Part I

There seemed to be enough confusion about this that I decided to document it in the hopes of helping someone else out moving forward. This post will be in a couple of parts. The first part addresses the now seemingly obvious step-by-step of getting the markup and JS laid in correctly so you can trigger the file upload dialog box using swfupload. The next episode will show getting the uploads into your application.

The Goal

Integrate the swfupload multiple file upload into a Rails application. Getting Started First of all, the current location for the swfobject code is at googlecode. For this post I used the most recent version, 2.2 Beta 5. 

Media_httpimgskitchco_lncyt

Read the rest of this post »

Fixture Replacement with Factory Girl (Sorry :quentin)

I've been working with fixture replacement objects for quite some time in my Rails testing, so the concept and the ease-of-use isn't new. The solution I've been using is a home-grown one implemented by a former colleague in response to discussions at work about how best to replace our store of seed data and fixtures but still get objects that are initialized to a set of reasonable (i.e., valid) defaults with the option to override. It was a good solution for us at the time. That said, I've heard a lot of buzz about Factory Girl. Given that I was setting up testing in a new project last night, I took the opportunity to explore it.

Read the rest of this post »

YUI DataTable With Rails

[Cross-posted on devchix] I am currently working on an Rails app that integrates the YUI dataTable, and in going through the tutorials I noticed they are all assume a PHP back-end. I also saw a number of people asking how to get this to work with a Rails controller, so I thought I'd write up my experience in the hopes that it helps someone else. For basic info about setting up the dataTable, refer to the YUI site, linked above. I'm also going to try to clarify a few things that I found a bit obscure.

Read the rest of this post »

Setting up Flash in Rails

Just a quick gotcha that got me tonight:
public/crossdomain.xml
public/movies/movie1.swf
Before I put my movies in their own subdirectory, i.e., when they were at the same level as crossdomain.xml, I was receiving a *** Security Sandbox Violation *** in the Flash Debug Console. After I put them in the movies/ directory, the violation went away. In short: # create a crossdomain.xml file And make it more secure than that -- that's only for development. # Put your movies below it # Load them into your app (I love haml):
%object{:width => "700", :height => "100"}
  %param{:name => "movie", :value => "movies/loggedInTest2.swf"}
    %embed{:src => "movies/loggedInTest2.swf", :width => "700", :height => "100"}