导轨 - 回形针验证附件大小时,它不应该是什么? [英] Rails - Paperclip validating attachment size when it shouldn't be?

查看:142
本文介绍了导轨 - 回形针验证附件大小时,它不应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用回形针,看起来像这样一个轨道模式:

  has_​​attached_file:图像:风格=> {:正常=> ['857x392#',:PNG]},
                    :URL => /assets/pages/:id/:basename.:extension,
                    :PATH => :RAILS_ROOT /公/资产/页/:ID /:基本名称:扩展名

  validates_attachment_size:图像:less_than => 2.megabytes
 

在试图建立这种模式的记录没有附件上传,则返回验证错误:

  

有问题与下列   字段:

  *图片文件大小文件大小必须在0到2097152字节之间。
 

我已经试过路过两个:allow_blank =>真实:allow_nil =>在模型验证后声明真实的,但也没有工作。

我怎么能允许:图像参数设置为空白。

解决方案
  

validates_attachment_size:图像:在=> 0.megabytes..2.megabytes

现在的作品

I've got a rails model using Paperclip that looks like this:

  has_attached_file :image, :styles => { :normal => ['857x392#', :png] },
                    :url => '/assets/pages/:id/:basename.:extension',
                    :path => ':rails_root/public/assets/pages/:id/:basename.:extension'

  validates_attachment_size :image, :less_than => 2.megabytes

When attempting to create a record of this model without an attachment to upload, the validation error is returned:

There were problems with the following fields:

* Image file size file size must be between 0 and 2097152 bytes.

I've tried passing both :allow_blank => true and :allow_nil => true after the validation statement in the model, but neither have worked.

How can I allow the :image parameter to be blank?

解决方案

validates_attachment_size :image, :in => 0.megabytes..2.megabytes

works now

这篇关于导轨 - 回形针验证附件大小时,它不应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆