Backport dependency tracking for Rails 3.2

Addresses https://github.com/rails/jbuilder/issues/126#issuecomment-31064642.

Unsure if this style is quite up to par - the constant to store a class reference was the best I could improvise right now. Feedback is very welcome.