New features in Rails 3.2

1 min read

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’) # => “


    [/source]
    But now we have it as
    [source language=”ruby”]
    form_for(@product, :as => ‘item’) # => “


    [/source]
    button_tag is new tag added to ActionView::Helpers::FormBuilder. Its just similar to submit_tag. An Example as
    [source language=”ruby”]
    <%= form_for @product do |f| %>
    <%= f.button %>
    <% end %>
    [/source]


* Better rails commands

    We have better Rails command line. Some of them are
    – Atributes takes string by default
    – Old plugin generator removed
    – Destroy alias added

* Changes in render template

    Now it is possible to provide :handlers and :formats directly as an options. An example
    [source language=”ruby”]
    render :template => edit, :formats => :html, :handlers => :erb
    [/source]

These are some of the changes I went through while going through the changelog. I hope this blog would be useful for knowing new changes in Rails 3.2. Let move forward in working with Rails 3.2 further

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *