Error messages from model


I have a model with the following validation:

validates_uniqueness_of :contact_id, :scope => :list_id

The validation works correctly and prevents duplicate records being
created that contain the same contact_id and list_id.

However, I can’t get the error message to appear on the submission form.

I have:

<%= error_messages_for ‘contact_list’ %>
enclosed within the form, but it’s only displaying flash[:notice]
messages from the controller.

How do I get to display error messages from the model?

For this to work you need to have an instance variable called @contact_list

So if it’s a user object that you’ve got errors on, and you’ve stuffed it into an @user instance variable, you would need to use

<%= error_messages_for ‘user’ -%>