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:


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

Related changeset:

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:


This little enhancement is courtesy of José Valim.

Related changeset:

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"

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

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

Related changeset:

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