Suffix

No more ‘error_messages_for’ in Rails 3

Ruby on Rails 3 depreciates the ‘error_messages_for’ method.

I played with the latest Rails 3 beta release today (version 3.0.0.beta4) and noticed the following depreciation warning:

DEPRECATION WARNING: form.error_messages was removed from Rails and is now available as a plugin.

Apparently the old ‘error_messages_for’ violated the core Rails principles of never dictating the look and feel of an application. Indeed, it includes fixed HTML and copywriting, not good.

Solution

The Rails core team decided to drop it completely as it’s just too easy to write a simple wrapper.

<% if @post.errors.any? %>
  <ul>
    <% @post.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
  </ul>
<% end %>

I hope this post saved someone a few minutes.

More resources