0

:thisユーザーがタイトルとまたはのいずれかを入力するように求められるフォームがあります:that。ユーザーは両方のフィールドに入力できません。

<% f.input :title%>
<% f.input :this %>
<% f.input :that%>

私のために私:titleは私のモデルに持っています

validates :title, :presence => true

の検証に合格するにはどうすればよいですかeither :this or :that

4

1 に答える 1

1

あなたはこれを行うことができます

validates :that, :presence => true, :if => Proc.new {this.blank?}
validates :this, :presence => true, :if => Proc.new {that.blank?}
于 2013-09-01T04:32:19.183 に答える