Exactly which content-inserting block helpers have changed behaviour in Rails 3?
Asked Answered
C

2

6

The release notes for Rails 3.0 include this change:

7.4.2 Helpers with Blocks

Helpers like form_for or div_for that insert content from a block use <%= now:

<%= form_for @post do |f| %>
   ...
<% end %>

Your own helpers of that kind are expected to return a string, rather than appending to the output buffer by hand.

Helpers that do something else, like cache or content_for, are not affected by this change, they need <% as before.

We're in the process of migrating a web application from Rails 2.3.18 to Rails 3.1.12, and it would be very useful to have a complete list of such helpers that have changed, so that we can check all of their occurrences in our source code, but I'm having trouble finding an authoritative list of this kind.

I've tried looking through the git history of the rails project, but there seem to be many commits with related changes, and they're not obviously grouped on particular branch. For example, it seems to be clear that this list includes:

  • form_for
  • form_tag
  • fields_for
  • field_set_tag

... from 7b622786f,

  • link_to

... alluded to in e98474096 and:

  • div_for
  • content_tag_for

... alluded to in e8d2f48cff

  • remote_form_for

.... alluded to in 0982db91f, although it's removed in Rails 3.

However, I'm sure that's not complete - can anyone supply a complete list?

Crippling answered 2/5, 2013 at 14:58 Comment(1)
Simplifying Rails Block Helpers by Yehuda Katz contains some information about the reasoning behind the decision and details about the low level implementation. It may provide some clues about where to look for the answer, sadly it doesn't contain a complete list of which helpers changed.Overburden
E
1

i don't have a complete list, but i think that you can derive most of what has changed from having a look at the diff in documentation of UrlHelper and FormHelper. most of the methods in those helpers changed to the new syntax.

http://apidock.com/rails/v2.3.8/ActionView/Helpers/UrlHelper/link_to http://apidock.com/rails/v2.3.8/ActionView/Helpers/FormHelper/form_for

Enosis answered 10/5, 2013 at 15:1 Comment(1)
Thanks for your answer - it's helpful, but it doesn't exactly answer my question as asked, as you acknowledge, since I am looking for a complete and authoritative (or at least carefully justified) list from somewhere / someone, rather than an indication of "most of what has changed".Crippling
C
0

There is a list of these methods in the rails_upgrade plugin, whose purpose is to check your application for problems on upgrading from Rails 2 to Rails 3. The relevant method is check_old_helpers, which checks for block helpers containing any of:

  • content_tag
  • javascript_tag
  • form_for
  • form_tag
  • fields_for
  • field_set_tag

As for how authoritative this is, this plugin is an official Rails project plugin, although it does miss out a couple that I found by searching the git history:

  • div_for
  • remote_form_for
  • link_to

However, if the official tool for checking for these helpers is missing some, perhaps this is as good a list as I'm likely to find. Another point is that the upgrade check tool mentions that there should be deprecation warnings if you miss some, which provides an additional check:

Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.

Crippling answered 1/6, 2013 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.