Rush to Rails 1.2 Adds Tons of New Features 12
The Rails Developers are rushing to get a 1.2 release out the door before RailsConf Europe. I'll try to list a quick run down of changes you'll may not be aware of in 1.2:
- Access nested attributes in RJS templates. Now you can use syntax like this: page[:foo][:style][:color] which will generate javascript like: $('foo').style.color
- Michael Koziarski is my hero for this change. If you've ever tried to use a 'quote' column in your model, you quickly found out that it conflicted with AR's quote column method. No longer is this an issue. def quote has been changed to def quote_value
- Calling image_tag without the file extension now raises a Deprecation warning. In 2.0, it will no longer append .png to the file name. This is welcome change, unneeded magic is well...unneeded.
- UPDATE: This change has been reverted for the time being. Now you can access the locals hash directly. In your partials, you can check if a local varialbe was passed in by doing:
if locals[:local_var] then ... - In 2.0, the default for foreign_keys will be the association name, rather than the class name. So if you specify a :class_name with no :foreign_key on your belongs_to associations, it will throw a Deprecation warning. The tests explain this pretty well:
def test_deprecated_inferred_foreign_key assert_not_deprecated { Company.belongs_to :firm } assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" } assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" } assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" } end - The Ruby/MySQL driver that ships with Rails has been updated to work with the new authentication in MySQL 4.1+. Of course, everyone uses the Ruby C bindings to MySQL right?
- My own patch to distance_of_time_in_words was applied. What does this mean to you? Nothing at all, I just wanted to tell you about it.
- Some nice additions to Prototype Element Handling. You can now traverse the DOM using the new Element.up, Element.down, Element.previous and Element.next methods. To make debugging easier, you can use Element.inspect. Check out the changeset for more useful changes.
Examples: <div id="sidebar"> -> $('nav').up() or $('menu').up('div') <ul id="nav"> -> $('sidebar').down() or $('sidebar').down('ul') or $('menu').previous() <li>...</li> -> $('sidebar').down(1) or $('sidebar').down('li') <li>...</li> -> $('sidebar').down(2) or $('sidebar').down('li', 2) or $('sidebar').down('li').next('li') <li class="selected">...</li> -> $('sidebar').down('li.selected') </ul> <ul id="menu"> -> $('sidebar').down('ul').next() - Rails will actually use the 500.html thats been sitting in public for awhile when your application fails to catch an exception not related to routing.
- In the testing department, assert_tag has been deprecated in favor of the new assert_select family of assertions.
- Another one of my patches got applied. radio_button_tag now generates a unique id attribute based on the name_value pattern.
- And plenty of other deprecation warnings throughout Rails...those you can figure out for yourself.
Are they adding the find_by helpers for foreign keys?