Forum: Ruby on Rails Validation and Single-Table Inheritance

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Derek H. (Guest)
on 2006-01-10 09:26
(Received via mailing list)
I'm seeing an inconsistent application of validation in a single-table
inheritance situation, and wanted to see if anyone else has seen this.

I have the following:

class Contact < ActiveRecord
  validates_presence_of :first_name
  ...
end

class EmployeeContact < Contact
  ...
end

If I do the following while running the server or in test mode, no
error occurs eventhough the first name is invalid:
@employee_contact.update_attributes({:first_name => ""'})

When I do the same in script/console, #update_attributes returns false
(an error occurs as expected).

If I add: validates_presence_of :first_name to the EmployeeContact
model, the validation does fail as expected.

Anyone have any ideas why the validation only works as expected in the
console?

Derek

--
Derek H.
HighGroove Studios - http://www.highgroove.com
Atlanta, GA | San Mateo, CA
Keeping it Simple.
404.593.4879
This topic is locked and can not be replied to.