Upgrading to Rails 3: Beware of the Object#tap pattern
The advent of Object#returning first, and Object#tap consequently, quickly lead to a very common and elegant pattern in the Rails community to scope a variable to a block in your template code.
Here’s a simple .erb file.
<% "Simone".tap |string| %> Hello, <%= string %>. <% end %>
Once executed, in Rails 2.3 the template renders the following content
Hello, Simone.
However, due to some internal changes in the way how Rails 3 handles block helpers, the same template in Rails 3 renders the following content.
Hello, Simone.Simone
Here’s a live example, yielding the String “USD“.

The template displays a USD string, after the Ruby block
The same statement also causes the following deprecation warning:
DEPRECATION WARNING: <% %> style block helpers are deprecated. Please use <%= %>.
The problem here is the Rails 3 compatibility layer which is responsible to help you migrate your code from Rails 2.3 to the new Rails 3 syntax. Apparently, whenever you are using a block which returns a not nil value, the compatibility layer classifies this behavior as a legacy block helper style.

Rails 3 showing deprecation warnings for Block Helpers
In the meantime of a real solution, you can use the following workaround.
Upgrading to Rails 3: You are using the old router DSL which will be removed in Rails 3.1
How to fix the DEPRECATION WARNING: You are using the old router DSL which will be removed in Rails 3.1.
Capistrano: Executing a command as root without using sudo
How to run a command in Capistrano as a root without using sudo.
The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented
The goal of this article is to feature a list of tips and changes you can already introduce in your Rails 2 application to anticipate the migration and make your code more compatible with Rails 3.
Unobtrusive JavaScript in Rails 3
How to upgrade your JavaScript codebase from Rails 2 to Rails 3 Unobtrusive JavaScript, with real jQuery examples included.
Recent Comments