Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

PIVOTAL LABS
Standup 2/9/09 – chaining associatons, use_rails_error_handling! and eager_load_paths

Interesting things

  • People seem to think it would be useful to chain associations in the same way that named scopes work. E.g., post.comments.authors. We might look at providing a patch to do so.

  • Rspec and Rails 2.2 modifies rails to not rescue exceptions as it normally does. To fix that, add the following to your tests:

describe ThingsController do
   before(:each) do
     controller.use_rails_error_handling!
   end
end
  • A project was running into a problem on non dev/test environments with rails 2.2 where if we did a db:drop and a subsequent db:create, the migrations were blowing up with an exception on the Rails::Initializer.run line in environment.rb. The models were being loaded before any of the migrations had run, thus failing because the tables didn’t exist. To work around this, add config.eager_load_paths = [] in your Rails::Initializer. It was suggested this was either a bug in 2.2.2 and/or a bad interaction with desert.

Comments
  1. Do you know how to set same controller behaviour in Merb? ;]

  2. Pat Nakajima says:

    Regarding the association chaining, it’s not tough to roll manually: http://gist.github.com/63041.

    With that being said, it’s probably a bad idea, since it’s *way* too easy to abuse (speaking as someone who has done [such things](http://pivotallabs.com/users/nick/blog/articles/283–strike-ten-things-i-hate-about-proxy-objects-strike-part-i)).

    A better idea might be identifying a missing join model, or even just de-normalization for de-normalization’s sake. Then again, it is a cool trick.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *