に検証エラーをトリガー:ペーパークリップは、私は私のペーパークリップのモデルでは、この機能を持って破壊する
def ratiocorrect
ratio = Paperclip::Geometry.from_file(image.queued_for_write[:original].path).width/Paperclip::Geometry.from_file(image.queued_for_write[:original].path).height
if ratio < 1.499 or ratio > 1.501
errors.add(:image,'ratio should be 4:3')
end
end
画像は3の比率がある場合には、チェックします。それを保存する前に2。
私はこれを強制:
validate :ratiocorrect
そして、それは完璧に動作します。
けれども、私は、私は次のエラーを取得する画像破壊したい:
undefined method `path' for nil:NilClass
ratio = Paperclip::Geometry.from_file(image.queued_for_write[:original].path).width/Paperclip::Geometry.from_file(image.queued_for_write[:original].path).height
アクションを破壊するために何も存在しないとして、それは、再びqueued_for_write
画像に対してチェックしているようですが。
作成または更新され、破壊されていない場合のみ検証できますか?
パーフェクト。ありがとうございました – Maxence