Rails 3.2 was released with lot of amazing changes. I recently read about new features which provides better and new tags, faster reloading in development, faster queries and so on. So let’s take a look of some of those interesting features
* Faster Reloading in Development
- We can only reload classes if their dependent files get changed. You can do this by setting reload_classes_only_on_change to true or false
[source language=”ruby”]
config.reload_classes_only_on_change = boolean_value
[/source]
* Better content_tag_for and div_for tag
- These tags can take collection of records as a argument itself instead of looping through it for each record. An example
Instead of the below code
[source language=”ruby”]
@products.each do |item|
content_tag_for(:li, item) do
Name: <%= item.name %>
end
end
[/source]
we can rewrite this as
[source language=”ruby”]
content_tag_for(:li,@products) do |item|
Name: <%= item.name %>
end
[/source]
* Smarter Layout rendering approach
- You can use default layout when you specify a layout with only and :except conditions and in those conditions fail. An example
[source language=”ruby”]
class ProductsController
layout ‘banner’ , :only => :new
end
[/source]
In this above case, you will be using your default layout(layouts/application) for rest of the action. If the new action request comes in, you will be rendered with banner layout.
* Tag Level changes
- form_for tag with :as option changes the values of css class and id as “#{action}_#{as}”. An Example
Previously it was
[source language=”ruby”]
form_for(@product, :as => ‘item’) # => “