Published by Simon Schoeters

No more error_messages_for in Rails 3

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.

After Googling around some I found out why. 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.


The Rails core team decided to drop it completely as it's just too easy to write a wrapper for:

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

I hope this post saved someone a few minutes.

More resources

  • Message by DHH concerning the removal reasons.
  • Plugin to restore the Rails 2.x behavior... if you really want to.