Living on the edge (of Rails) #22 - pre-Railsconf 2008 edition

No mind-blowing changes in Rails this week prior to RailsConf - as Gregg mentioned last week in the Rails Envy podcast, it’s pre-2.1 days (Rails 2.1 will probably be released at RailsConf) so it’s pretty easy to see why. Oh and all Rails tests now pass in Ruby 1.9 after a long-standing #module_eval bug got fixed in Ruby 1.9’s trunk (see thread for more details).

I’ll be at (my first) Railsconf 2008 in Portland, Oregon this Thursday onwards - if anyone sees me and recognizes me from my Facebook picture please come and say hi (no head butting though).

This week’s report covers changes from 19th May 2008 to 25th May 2008 (the day the corresponding Rails Envy podcast was recorded).

first and last methods now work with associations and named_scope

Remember how the merging of the has_finder gem into Rails allowed you to do things like Post.first and Post.last?

Now you can go one step further and use the same methods on your ActiveRecord associations. For example:

post = Post.find(1)
first_comment = post.comments.first

If you have a named_scope named recent defined, you can even do this:

post.comments.recent.last

This neat little enhancement is courtesy of Ryan Bates (yes, that Ryan Bates of Railscasts fame).

Related changeset: http://github.com/rails/rails/commit/73c59638549686fccc749ffd3ac53cb533c5fd61

Cache stores now have an exist? method and controllers get fragment_exist?

The cache stores in Rails (Memcache, file stores, etc.) now have an exist? method that checks whether a cached value exists given a cache key. This allows Rails controllers to expose a fragment_exist?
method that allows you to check for existence of a cache fragment:

fragment_exist?('example.com/foo/bar')

This little enhancement is courtesy of José Valim.

Related changeset: http://github.com/rails/rails/commit/99860b72aebe0348f41e82d4710343498d89a84b#diff-2

Create association records with block argument

You can now create records for associations like so:

post.coments.create!(:title => 'Techcrunch') do |c|
  c.body = "Rails can't scale"
end

This is in keeping with the ActiveRecord::Base.create change previously mentioned.

Credit for this patch goes (once again) to Ryan Bates.

Related changeset: http://github.com/rails/rails/commit/6cba97d2a449faf21aec9fe9d4434067e414226f

As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.

2 Comments & TrackBacks (Add yours)

Paper doll icon
A Fresh Cup » Blog Archive » Double Shot #215's Gravatar

[…] Living on the Edge (of Rails) #22 - The big news this time is that all the tests for Rails now pass in Ruby 1.9. […]

Posted by: A Fresh Cup » Blog Archive » Double Shot #215 on May 26, 2008 6pm

Paper doll icon
Nome do Jogo » Artigo » Rails Podcast Brasil - Epis?dio 18's Gravatar

[…] redemption in a blog :: Living on the edge (of Rails) #22 ? pre-Railsconf 2008 edition […]

Posted by: Nome do Jogo » Artigo » Rails Podcast Brasil - Epis?dio 18 on May 29, 2008 12am

You can subscribe to the RSS feed for comments on this post.

Post a comment

(required)

(required, but never displayed)


You can format your comments using XHTML. Your email address will not be displayed or used for nefarious purposes.

Only following tags are allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>