Reputation: 7941
I have a form where the user is prompt to enter a title and either :this
or :that
. A user can't enter both fields.
<% f.input :title%>
<% f.input :this %>
<% f.input :that%>
for my :title
i have in my Model
validates :title, :presence => true
How can i pass a validation for either :this or :that
Upvotes: 0
Views: 91
Reputation: 51
Wouldn't just the first line be sufficient?
validates :that, :presence => true, :if => Proc.new {this.blank?}
If 'this' is blank and so is 'that', the first line would fail validation, so you wouldn't need the second line.
Upvotes: 0
Reputation: 5111
You can do this
validates :that, :presence => true, :if => Proc.new {this.blank?}
validates :this, :presence => true, :if => Proc.new {that.blank?}
Upvotes: 1