errors.add

how do i add errors manually to an object so they show up in the same list as the validations?

i tried errors.add - and it adds the error, but it doesn't stop the object from being saved like a validates_presence_of would

Jimmy Palmer wrote:

how do i add errors manually to an object so they show up in the same list as the validations?

i tried errors.add - and it adds the error, but it doesn't stop the object from being saved like a validates_presence_of would

define your own validate() method in your model, the errors you add there will show up and a failure will prevent the save.

hth

ilan

Ilan Berci wrote:

Jimmy Palmer wrote:

how do i add errors manually to an object so they show up in the same list as the validations?

i tried errors.add - and it adds the error, but it doesn't stop the object from being saved like a validates_presence_of would

define your own validate() method in your model, the errors you add there will show up and a failure will prevent the save.

hth

ilan

can you further explain how I might do this?

Jimmy Palmer wrote:

Ilan Berci wrote:

Jimmy Palmer wrote:

how do i add errors manually to an object so they show up in the same list as the validations?

i tried errors.add - and it adds the error, but it doesn't stop the object from being saved like a validates_presence_of would

define your own validate() method in your model, the errors you add there will show up and a failure will prevent the save.

hth

ilan

can you further explain how I might do this?

class SomeModel < ActiveRecord::Base

  def validate     errors.add(:world, "the world is not flat!") if self.world.flat?   end end

Ilan Berci wrote:

Jimmy Palmer wrote:

Ilan Berci wrote:

Jimmy Palmer wrote:

how do i add errors manually to an object so they show up in the same list as the validations?

i tried errors.add - and it adds the error, but it doesn't stop the object from being saved like a validates_presence_of would

define your own validate() method in your model, the errors you add there will show up and a failure will prevent the save.

hth

ilan

can you further explain how I might do this?

class SomeModel < ActiveRecord::Base

  def validate     errors.add(:world, "the world is not flat!") if self.world.flat?   end end

yeah, I tried that, but it still did not display the error and allowed the object to save. Do I need to manually check if there are errors and manually display them?