Rails setting OR conditions in validate_presence_of in a model?
Posted
by Jty.tan
on Stack Overflow
See other posts from Stack Overflow
or by Jty.tan
Published on 2010-06-03T02:14:54Z
Indexed on
2010/06/03
2:24 UTC
Read the original article
Hit count: 240
In a rails model, is it possible to do something like
class Example < ActiveRecord::Base
#associations
validates_presence_of :item_id, (:user_id OR :user_email)
#functions
end
Where the model has 3 columns of :item_id
, :user_id
, and :user_email
?
I want the model to be valid as long as I have a :user_id
or a :user_email
.
Idea being that if the item is recommended to a person who isn't currently signed up, it can be associated via email address for when the recommended person signs up.
Or is there a different method that I can use instead?
© Stack Overflow or respective owner