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
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 P. 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 B. wrote:
Jimmy P. 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 woulddefine 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 P. wrote:
Ilan B. wrote:
Jimmy P. 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 woulddefine 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 B. wrote:
Jimmy P. wrote:
Ilan B. wrote:
Jimmy P. 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 woulddefine 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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs