Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 验证附件fu中的图像尺寸_Ruby On Rails_Attachment Fu - Fatal编程技术网

Ruby on rails 验证附件fu中的图像尺寸

Ruby on rails 验证附件fu中的图像尺寸,ruby-on-rails,attachment-fu,Ruby On Rails,Attachment Fu,保存图像后,图像的高度和宽度将正确保存在模型中。我需要在保存之前验证图像的尺寸。它必须具有完全相同的尺寸。但是,当我在保存之前尝试访问高度或宽度时,它会给我零 我有什么办法可以做到这一点吗 现在,我在保存后给出一个警告,图像不是所需的尺寸。但这还不够整洁。我不确定附件的内容,但真正的图像可能是在保存前保存在中,或者在保存后保存在中。在保存图像之前运行验证 在验证之前使用回调来强制处理图像。我在验证之后使用对我不起作用。因此,我基本上做的是在验证后检查钩子中的尺寸,并让它使用@image.erro

保存图像后,图像的高度和宽度将正确保存在模型中。我需要在保存之前验证图像的尺寸。它必须具有完全相同的尺寸。但是,当我在保存之前尝试访问高度或宽度时,它会给我零

我有什么办法可以做到这一点吗


现在,我在保存后给出一个警告,图像不是所需的尺寸。但这还不够整洁。

我不确定附件的内容,但真正的图像可能是在保存前保存在
中,或者在保存后保存在
中。在保存图像之前运行验证


在验证之前使用
回调来强制处理图像。

我在验证之后使用
<验证前的代码>对我不起作用。因此,我基本上做的是在验证后检查
钩子中的尺寸,并让它使用
@image.errors.add\u到\u base(“图像需要精确到137x52像素)。
。我以下面的方式保存了图像

@image.valid? # Run the validations, which calls my hook method after_validation
@image.save if @image.errors.empty?