2009年5月3日 星期日

Rails 2.3 release notes

Ruby on Rails 2.3 Release Notes

1. Session stores are now lazy loaded. If you never access the session object during a request, it will never attempt to load the session data (parse the cookie, load the data from memcache, or lookup an Active Record object).

2. ActiveRecord::QueryCache middleware is automatically inserted onto the middleware stack if ActiveRecord has been loaded. This middleware sets up and flushes the per-request Active Record query cache.

3. The Rails router and controller classes follow the Rack spec. You can call a controller directly with SomeController.call(env). The router stores the routing parameters in rack.routing_args.

4. Instead of config.action_controller.session = { :session_key => 'foo', ... use config.action_controller.session = { :key => 'foo', ....



Nested Attributes, Nested Object Forms
Rails 2.3 前的 nested model/complex forms problem 都是這樣做
What's New in Edge Rails: Nested Model Mass Assignment

2.3 之後可以這樣做了
What's New in Edge Rails: Nested Object Forms
Nested Model Forms



Nested Transactions



Multiple Conditions for Callbacks
When using Active Record callbacks, you can now combine :if and :unless options on the same callback, and supply multiple conditions as an array:




Find with having
mysql group_by having
MYSQL GROUP BY 和 HAVING 子句

HAVING子句可以讓我們篩選成組後的各組數據.
WHERE子句在聚合前先篩選記錄.也就是說作用在GROUP BY 子句和HAVING子句前.
而 HAVING子句在聚合後對組記錄進行篩選。

Rails now has a :having option on find (as well as on has_many and has_and_belongs_to_many associations) for filtering records in grouped finds. As those with heavy SQL backgrounds know, this allows filtering based on grouped results:




Reconnecting MySQL Connections
mysql Controlling Automatic Reconnection Behavior
MySQL supports a reconnect flag in its connections – if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set reconnect = true for your MySQL connections in database.yml to get this behavior from a Rails application



Application Controller Renamed

If you’re one of the people who has always been bothered by the special-case naming of application.rb, rejoice! It’s been reworked to be application_controller.rb in Rails 2.3. In addition, there’s a new rake task, rake rails:update:application_controller to do this automatically for you – and it will be run as part of the normal rake rails:update process.



HTTP Digest Authentication Support

For those that may now know the difference, basic authentication only base 64 encodes the authenticating username and password (making it easily decoded) whereas digest authentication sends an MD5 hash of your username and password. To simplify, digest is more secure than basic.

What's New in Edge Rails: HTTP Digest Authentication



More Efficient Routing

Another big change is that Rails now supports multiple routing files, not just routes.rb. You can use RouteSet#add_configuration_file to bring in more routes at any time – without clearing the currently-loaded routes. While this change is most useful for Engines, you can use it in any application that needs to load routes in batches.



Rack-based Lazy-loaded Sessions

In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). This means that you no longer need to explicitly disable sessions if you don’t want them; just don’t refer to them and they won’t load.



MIME Type Handling Changes

There are a couple of changes to the code for handling MIME types in Rails. First, MIME::Type now implements the =~ operator, making things much cleaner when you need to check for the presence of a type that has synonyms:

The other change is that the framework now uses the Mime::JS when checking for javascript in various spots, making it handle those alternatives cleanly.



Asset Hosts as Objects

Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to to implement any complex logic you need in your asset hosting.



grouped_options_for_select Helper Method





Disabled Option Tags for Form Select Helpers

New in rails 2.3 – disabled option tags and lambdas for selecting and disabling options from collections



Swappable Parsers for XMLmini

The support for XML parsing in ActiveSupport has been made more flexible by allowing you to swap in different parsers. By default, it uses the standard REXML implementation, but you can easily specify the faster LibXML or Nokogiri implementations for your own applications, provided you have the appropriate gems installed:




Faster Boot Time in Development Mode with Lazy Loading/Autoload

Quite a bit of work was done to make sure that bits of Rails (and its dependencies) are only brought into memory when they’re actually needed. The core frameworks – Active Support, Active Record, Action Controller, Action Mailer and Action View – are now using autoload to lazy-load their individual classes. This work should help keep the memory footprint down and improve overall Rails performance.

You can also specify (by using the new preload_frameworks option) whether the core libraries should be autoloaded at startup. This defaults to false so that Rails autoloads itself piece-by-piece, but there are some circumstances where you still need to bring in everything at once – Passenger and JRuby both want to see all of Rails loaded together.

沒有留言: