This project is archived and is in readonly mode.

#5413 ✓stale
Elliot Crosby-McCullough

Overactive block helper deprecation warning when iterating on an ActiveModel::Errors object

Reported by Elliot Crosby-McCullough | August 19th, 2010 @ 09:07 PM

During the switch over from <% style block helpers to <%= style something appears to have gone awry.

In the following ERB, the flash.each_pair line does not generate a deprecation warning, however the messages.each_pair line does.

    <% flash.each_pair do |flash_type, messages| %>
      <ul class="<% flash_type %> flash">
        <% messages.each do |_, message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    <% end %>

At this point, flash is (I assume) a standard hash, at least whatever Rails provides, whereas messages is an ActiveModel::Errors object.

Since ActiveModel::Errors#each yields, it's correct to use the old-style block notation. Any return value is undefined (and its output unwanted). Unfortunately, Rails emits a deprecation warning for this object.

This behaviour is identical for ERB and Haml.

Regards,
Elliot Crosby-McCullough

Comments and changes to this ticket

  • Brent Greeff

    Brent Greeff December 23rd, 2010 @ 09:46 PM

    I am seeing something similar,

    If I have a content_for block, with an if statement inside,
    when the if statement fails I get the deprecation warning.

    If I change the if statement to the following:

    <% content_for :something %>

    <% if sunny? %>
    say hello <% else %>

    <% end %>

    <% end %>

    The warning goes away.

    Seems a plain old tab character will do the trick.

  • rails

    rails March 24th, 2011 @ 12:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails March 24th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages