Last updated

Why did error_messages_for disappear from Rails 3?

Today I learned that error_messages_for has disappear from Rails 3. When I tried using it I got the following deprecation warning:

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

What happened? Why was this pulled from Rails 3? ~ The reason error_messages_for was pulled from Rails 3 is a new guideline that says that nothing in Rails Core should dictate the look and feel of an app.

Okay, that’s all well and good. How do you fix this problem? There are two ways. The first is to implement your own error handling. A HAML snippet:

1- if @post.errors.any?
2  .errors
3    %h2 There was a problem saving this post
4
5    %ul
6      - @post.errors.full_messages.each do |msg|
7        %li= msg

This is by far the best way to go about it. However, if you have a current Rails 2 app you’re upgrading, writing your own error handling may be rather difficult or time consuming. In that case you can install a plugin that restores the original functionality of error_messages_for.

1rails plugin install git://github.com/rails/dynamic_form.git

Just make sure to restart your server.

Tags: rails3