Error messages from model

0 views
Skip to first unread message

David Lelong

unread,
Oct 2, 2006, 11:12:37 PM10/2/06
to rubyonra...@googlegroups.com
Hi,

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?

Thanks,

David

--
Posted via http://www.ruby-forum.com/.

Daniel N

unread,
Oct 2, 2006, 11:28:57 PM10/2/06
to rubyonra...@googlegroups.com
On 10/3/06, David Lelong <rails-mai...@andreas-s.net> wrote:

Hi,

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' -%> 


Reply all
Reply to author
Forward
0 new messages