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

In: Edge Rails|Open Source|Ruby|Ruby on Rails

25 May 2008

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.

5 Responses to Living on the edge (of Rails) #22 – pre-Railsconf 2008 edition

Avatar

A Fresh Cup » Blog Archive » Double Shot #215

May 26th, 2008 at 6pm

[…] 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. […]

Avatar

Nome do Jogo » Artigo » Rails Podcast Brasil - Epis?dio 18

May 29th, 2008 at 12am

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

Avatar

roger

August 19th, 2008 at 2pm

I guess this answers the question “does rails work on ruby 1.9”

Avatar

mikeyaozm

October 3rd, 2009 at 4pm

Yeah, a wee bit unfortunate that. Had similar high hopes blasted with the Ruby Shootout announcement recently

Avatar

cheap michael kors bags

August 18th, 2014 at 5pm

If You Still Desire To Purchase A Classic michael kors handbags,
We Recommend Our michael kors handbags Offers You High Quality And Big Discount!

more from :cheap michael kors bags

Comment Form