I'm gonna post up the Living on the Edge a little earlier this week because I've found I just can't keep up (when things get busy) with 2 separate sets of notes for the Rails Envy podcast and another for my own blog posts.
From this week onwards, I'll be following Pratik's suggestion to post about changes as they happen instead of after an entire week so expect a slight change in the format of Living on the edge for next week!
This week’s report covers changes from 31 Mar 2008 to 6 Apr 2008 (the day the corresponding Rails Envy podcast was recorded).
Rails.env, Rails.logger, Rails.cache, Rails.root
This has been a long time coming: You can now use
Rails.env instead of
Rails.root instead of
Rails.logger instead of
Rails.cache instead of
RAILS_CACHE. Not having to use constants is nice because it always felt a bit dirty to have so many hard-coded constants in the Rails namespace.
Credit goes to Pratik Naik, the newest Rails core team member for this cleanup.
Related changeset: http://dev.rubyonrails.org/changeset/9180
Render :partial now works with a collection of heterogeneous elements
You can now use
render :partial to render a collection of different elements and Rails will figure out which partial template to use. For example:
render :partial => [ monkey, donkey, dramatic_chipmunk ]
will render the monkey with the 'monkeys/_monkey.html.erb' partial, donkey with the 'donkeys/_donkey.html.erb' partial, and last but definitely not lest, dramatic_gopher with the 'dramatic_chipmunks/_dramatic_chipmunk.html.erb' partial
This is especially useful if when using STI, where your ActiveRecord model would return objects of different types. The collection
[ monkey, donkey, dramatic_chipmunk ] could very well be something returned from your
Animal model that has subclasses of
DramaticChipmunk via STI.
Related changeset: http://dev.rubyonrails.org/changeset/9177
ActiveModel work revived
It seems like work on ActiveModel (think unified ActiveRecord and ActiveResource behaviors) has been revived, if the latest commits (http://dev.rubyonrails.org/changeset/9171 and http://dev.rubyonrails.org/changeset/9173) by David (DHH) is anything to go by.
Bugfix: Assigning an invalid has_one association now causes #save to fail on parent
You could do this before:
firm = Firm.find(:first) firm.account = Account.new # Associate INVALID account firm.save # This doesn't fail
Now that's fixed thanks to Pratik Naik.
Related changeset: http://dev.rubyonrails.org/changeset/9232
As usual, any feedback is respectfully appreciated!