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

Custom JavaScript and stylesheet symbols

Remember how you can do something like:

javascript_include_tag :defaults

and Rails would load all the Prototype JavaScript files and your application.js?

You can now register your own custom expansion symbol too:

# In a Rails initializer.
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :yui => ['yahoo', 'autocomplete', 'calendar']

# In your view.
javascript_include_tag :yui

would result in:

<script type="text/javascript" src="/javascripts/yahoo.js"></script>
<script type="text/javascript" src="/javascripts/autocomplete.js"></script>
<script type="text/javascript" src="/javascripts/calendar.js"></script>

You can do the same with the stylesheet_link_tag by registering a custom expansion symbol via register_stylesheet_expansion.

This is useful for anyone but in particular plugin developers who have a multiple asset files would appreciate being able to tell users to include JavaScript or stylesheets using a single symbol.

Warning: This patch currently breaks the default symbols like :all (check out the ticket for more info).

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

Sexy default timestamps in migrations

Remember how you can say timestamps in a migration and Rails will create the 'created_at' and 'updated_at' columns for you? You can now also do add_timestamps :table_name and remove_timestamps :table_name in your migrations if you decide to add these columns later to a table:

def self.up
  add_timestamps :posts
end

def self.down
  remove_timestamps :posts
end

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

ActiveRecord::Base#find(:last)

Just like Comment.find(:first), you can now do something like Comment.find(:last). There's some controversy over whether this is bloat, but DHH makes a good case for it with this example:

class Person
  has_many :comments, :order => 'created_at'
end

@some_person.comments.find(:last) # => Returns the most recent comment.

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

Database rake tasks fixes

rake db:create used to ignore the 'charset' and 'collation' options in your database.yml configuration file. This has been fixed so that your created databases now respect those options.

rake db:drop and rake db:migrate:reset also no longer crash with an unhelpful exception if the database has already been dropped, and instead shows a proper error message.

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

Rails' logger now creates the log directory if it doesn't exist

This is a blessing to those of us who use version control systems that don't support empty directories (like Git). Rails' default logger (the BufferedLogger), now creates a log/ directory if it doesn't already exist. This should save you the step of creating/symlinking a log/ directory (or symlinking) on deploy.

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

String#squish is faster

A faster implementation of the String#squish (and String#squish!) core extension has been committed.

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

The #excerpt TextHelper no longer includes 1 character too many

Turns out that the #excerpt helper method was consistently including an extra character. This has been fixed.

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

As usual, let me know of any inaccuracies or any suggestions you may have in the comments!