Sunday, October 26, 2008

1 error prohibited this user from being saved - rails form error_messages

If you have validated errors you can see the following messages:

1 error prohibited this user from being saved
there were problems with the following fields:
....

annoying and not very accurate - aren't they?

If you want to change these default messages try to pass some extra params to the error_messages method:
form_for(@user,:url => { :action => "login" }) do |f| %>
f.error_messages(
:header_message => 'X errors, please find red marks',
:message => 'Following errors were found:')

4 comments:

  1. Thanks - very userfull!

    ReplyDelete
  2. This declaration on the form doesn't work for me.
    Instead, the following helps when displaying the error messages:
    error_messages_for :user, :header_message => 'X errors, please find red mark', :message => 'Following errors were found:'

    ReplyDelete
  3. how to get the value of X errors?

    ReplyDelete
  4. came across your blog ... thanks for the post - that was exactly what i was looking for.

    ReplyDelete