Topic: Active Record error messages double? (i.e twice)

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?

Re: Active Record error messages double? (i.e twice)

Does it matter if you do observe :employee instead of observe Employee? It may be the difference between a class and an instance?

Last edited by pullmonkey (2008-01-17 12:20:41)

Re: Active Record error messages double? (i.e twice)

Im not sure about object But i saw many places it is Active record class only

My issue is I'm getting the error messages two times in Employee Model

Like Name Can't be blank, Name Can't be blank,

This is happening in production and testing environment only not in the development

Re: Active Record error messages double? (i.e twice)

Any ideas please?

Re: Active Record error messages double? (i.e twice)

Right, so you assume it has nothing to do with the observe. 
Then can you post your view for the form and your controller code?

Re: Active Record error messages double? (i.e twice)

Hi My controller code is very big  it is not clear

I'm giving the same example in models

class Employee< ActiveRecord::Base
  validates_presence_of :name,:value
  validates_numericality_of :value
  validates_uniqueness_of :value,:name
 
  has_many :issues
end

module EmployeeSpecHelper   
     def valid_employee_attributes 
        {
          :id=>1,
          :name=>"Reported" ,         
          :value=> 1
        }   
     end     
   end   
   
  describe Employee do
  fixtures :employees
  include EmployeeSpecHelper
 
  before(:each) do
    @employee = Employee.new   
  end
   
  it "should be invalid without a name"do 
    @issue_employee .attributes = valid_employee _attributes
    @issue_employee .name = nil
    @employee .should_not be_valid     
    @employee .errors.on(:name).should eql("can't be blank")     
    @employee .name = 'somename'         
   
  end
end

Im getting no errors when i run the rake:spec controoler

But when i run rake:spec (i.e controller and models)
the erro rmessages are getting twice
like " can't be blank ,can't be blank"

In all models same like this only
Any ideas?

Re: Active Record error messages double? (i.e twice)

SOLVED...

Had identical problem, my 'members' model would spit out errors twice...

Then, started doing it three times!

In the meantime while working on my member model, troubleshooting what is wrong, I kept making copies of members.rb model file! THIS WHAT CAUSED THE MULTIPLE ERRORS!!! When I had 'members copy.rb' file next to my original model, errors would show twice. Removed all two copies of the original and no more problems!

SAVE MYSQL NOW, Go to: http://helpmysql.org

Re: Active Record error messages double? (i.e twice)

I got the same problem when load (instead of require) models in Spork.each_run

# reload models
#
Dir[Rails.root.join("app/models/*.rb")].each { |f| require f }

Last edited by xzif (2012-03-23 06:17:00)