Living on the edge (of Rails) #14 – the extreme edition. Extremely late.

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

5 Apr 2008

This week’s report covers changes from 24 Mar 2008 to 30 Mar 2008 (the day the corresponding Rails Envy podcast was recorded).

There’re lots of big exciting changes this week on edge. Smells like 2.1 soon!

has_finder gem merged into Rails

Ryan Daigle has the scoop on the new has_finder-like functionality in Rails so head on over (I won’t repeat it here in the interests of DRY).

Credit goes to Nick Kallen for coming up with the has_finder gem.

Related changeset: http://dev.rubyonrails.org/changeset/9084

ActiveRecord: Unsaved attribute changes are now tracked

You can now ask an ActiveRecord model whether its attributes have been changed (and is unsaved) using the {attr_name}_changed? (magic) method. The {attr_name}_was method will return the original value of the attribute, and the {attr_name}_change method will return an array with 2 members, the 1st being the original value, the 2nd being the changed (and unsaved) value.

# Change person's name.
person.name = 'Jason Seifer'
person.changed?       # => true
person.name_changed?  # => true
person.name_was       # => 'jseifer'
person.name_change    # => ['jseifer', 'Jason Seifer']
person.name = 'Ceiling Cat'
person.name_change    # => ['jseifer', 'Ceiling Cat']

Credit goes to Rails core team member Jeremy Kemper (bitsweat) for this patch (which originated from Jeremy’s very own Dirty plugin).

Related changeset: http://dev.rubyonrails.org/changeset/9127

ActiveRecord#Base.all/first/last

Now you can do:

Post.all.each { |post| # something }
Post.first
Post.last

Kinda like how some other ORMs do (like DataMapper).

Credit: thechrisoshow and again, Nick Kallen for has_finder.

Related changeset: http://dev.rubyonrails.org/changeset/9085

Timestamped Migrations

This is more useful than it sounds: migrations are now timestamped instead of using incremental numbers in your db/migrate folder. This eliminates the problem of migrations having the same version number when working on a multi-developer Rails app.

Two new Rake tasks, rake db:migrate:up/down, have been added to allow running of the up and down methods of individual migrations.

Credit goes to John Barnette, the guy who gave you foxy fixtures.

Related changeset: http://dev.rubyonrails.org/changeset/9122

New config.gem option for specifying which gems are required by the application + rake tasks for installing and freezing gems

Specify which gems are required by your Rails app in your Rails environment.rb! “Vendor everything” supported right in Rails :). An example:

Rails::Initializer.run do |config| 
  config.gems 'chronic'
  config.gems "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  config.gems "aws-s3", :lib => "aws/s3"
end

There are also new Rake tasks:

# List required gems. 
rake gems 

# Install all required gems: 
rake gems:install 

# Unpack specified gem to vendor/gems/gem_name-x.x.x 
rake gems:unpack GEM=chronic

Credit goes to the prolific Rick Olson for this gem of a patch.

Related changeset: http://dev.rubyonrails.org/changeset/9140

ActiveResource #clone

You can now clone an existing resource:

gregg = Person.find(1)
borg = gregg.clone

This doesn’t clone child ActiveResource members though, just the straight up attributes of resource.

Contribors: Ryan Daigle and thechrisoshow.

Related changeset: http://dev.rubyonrails.org/changeset/9121

Big documentation patch

A big doc patch consisting of all the efforts going on in the doc-rails repository on Github has been committed. Check out Pratik’s post for more info on what doc-rails is. Though with Rails moving to Git soon, doc-rails may no longer be necessary!

Related changeset: http://dev.rubyonrails.org/changeset/9093

4 Responses to Living on the edge (of Rails) #14 – the extreme edition. Extremely late.

Avatar

A Fresh Cup » Blog Archive » Double Shot #181

April 7th, 2008 at 7pm

[…] Living on the Edge (of Rails) #14 and #15 – More news from the front. […]

Avatar

Rails Podcast Brasil - Epis?dio 12

April 7th, 2008 at 9pm

[…] Living on the edge (of Rails) #14 ? the extreme edition. Extremely late. […]

Avatar

Living on the edge (of Rails) #22 - pre-Railsconf 2008 edition | redemption in a blog

June 20th, 2008 at 1pm

[…] how the merging of the has_finder gem into Rails allowed you to do things like Post.first and […]

Avatar

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

November 10th, 2009 at 2pm

[…] how the merging of the has_finder gem into Rails allowed you to do things like Post.first and […]