Active record error messages are Double?

804 views
Skip to first unread message

Karni Karni

unread,
Jan 17, 2008, 6:18:13 AM1/17/08
to rubyonra...@googlegroups.com
Hi Friends

I have two below classes

class Employee< ActiveRecord::Base
validates_presence_of :name,
........
end
other
class AuditObserver < ActiveRecord::Observer
observe Employee

........
end

But when we are creating the Employee record form create view

All predefined error messages are twice

Means validation error

# Name can't be blank
# Name can't be blank

Could please give any advice on it ? Why the error messages are
Double?
--
Posted via http://www.ruby-forum.com/.

Aaron

unread,
Jan 17, 2008, 11:51:34 AM1/17/08
to Ruby on Rails: Talk
Are you calling require 'employee' anywhere? If so you are likely
causing the model to load twice which causes duplicate errors because
the validates_presence_of method gets called twice.

Aaron

Mark Wilden

unread,
Jan 17, 2008, 1:04:28 PM1/17/08
to Ruby on Rails: Talk
But #require shouldn't load employee twice, unless it's given two
different paths, right?

///ark

Aaron

unread,
Jan 17, 2008, 1:46:01 PM1/17/08
to Ruby on Rails: Talk
I had the exact same problem as described in the original post. I
tracked it down to some explicit require statements I had at the top
of one of my models. When I removed the requires the double error
messages went away.

You are right that "require" will only load the file once. But if you
load the class another way calling "require" will load it again.

Aaron

Karni Karni

unread,
Jan 22, 2008, 6:58:32 AM1/22/08
to rubyonra...@googlegroups.com
I didn't call require in any models

But I have called require in employee controller

Is that any problem?

But the error messages twice in only testing , production
Error messages are fine in development mode

Roger Pack

unread,
Apr 16, 2008, 2:26:53 AM4/16/08
to rubyonra...@googlegroups.com
ash.christopher wrote:
> I am having the same issue. I do not have any extra requires. Has
> anyone found a solution to this issue? I am using the basic
> scaffolding generated by rails.
>
> On Jan 17, 7:18�am, Karni Karni <rails-mailing-l...@andreas-s.net>

try production mode?

Roger Pack

unread,
Apr 16, 2008, 10:19:43 AM4/16/08
to rubyonra...@googlegroups.com
Karni Karni wrote:
> I didn't call require in any models
>
> But I have called require in employee controller
>
> Is that any problem?
>
> But the error messages twice in only testing , production
> Error messages are fine in development mode

maybe calling 'require_dependency' instead of 'require' would help?

Bharath Brahma

unread,
Jun 28, 2013, 6:18:47 AM6/28/13
to rubyonra...@googlegroups.com, rails-mai...@andreas-s.net
Thanks a lott Roger Pack
Including via require_dependency rather than require does solve the mystery..:)
Reply all
Reply to author
Forward
0 new messages