別のフィールドが存在する場合、クリップの添付ファイルが存在しないことを確認するにはどうすればよいですか? 私は試した:
validates_attachment :img, presence: false, if: :some_other_field?
def some_other_field?
some_other_field
end
別のフィールドが存在する場合、クリップの添付ファイルが存在しないことを確認するにはどうすればよいですか? 私は試した:
validates_attachment :img, presence: false, if: :some_other_field?
def some_other_field?
some_other_field
end
ここで同様の問題、私の解決策は定義で比較することでした
validate :check_image_with_title
def check_image_with_title
if !ctitle.blank? and cimage.blank?
#If ctitle IS NOT empty and cimage IS empty, add a custom error message
errors.add :key, "You need an image to go with your title"
return false
else
return true
end
end
これを試して:-
validates_attachment :img, presence: true, if: :some_other_field?
def some_other_field?
some_other_field.present?
end
exists?
代わりに使用しようとしましたかpresent?
、動作する可能性があります
validates_attachment :img, presence: false, if: :some_other_field?
def some_other_field?
some_other_field.exists?
end