Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5413

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Brent Greeff
    Brent Greeff

    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.

    December 23rd, 2010 @ 09:46 PM

  2. rails
    rails
    • 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.

    March 24th, 2011 @ 12:00 AM

  3. rails
    rails
    • State changed from open to stale

    March 24th, 2011 @ 12:00 AM