加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Ruby on Rails PaperClip Gem validate_attach

发布时间:2020-12-16 20:02:06 所属栏目:百科 来源:网络整理
导读:我有谷歌/堆栈溢出了几个小时,没有找到解决这个问题的办法.我想知道我的安装PaperClip是不成功的.我正在验证我的模型文件夹中的图像附件: validates :image,presence: true,content_type: { content_type: ['image/jpeg','image/jpg','image/png','image/gi
我有谷歌/堆栈溢出了几个小时,没有找到解决这个问题的办法.我想知道我的安装PaperClip是不成功的.我正在验证我的模型文件夹中的图像附件:
validates :image,presence: true,content_type: { content_type: ['image/jpeg','image/jpg','image/png','image/gif']},size: { less_than: 5.megabytes }

我也尝试过与github上的read me文件相似的代码:

validates_attachment :image,:presence => true,:content_type => { :content_type => 'image/jpeg','image/gif' },:size => { less_than: => 5.megabytes }

我试图使用单独的验证

validates_attachment_presence :image
validates_attachment_content_type :image,:content_type => ['image/jpeg','image/gif']
validates_attachment_size :image,:less_than => 5.megabytes

我在所有情况下都会收到错误.或者:

Routing Error
undefined method `before_image_post_process' for #<Class:0x00000101461750>
Try running rake routes for more information on available routes.

要么:

NoMethodError in PinsController#index
undefined method `key?' for nil:NilClass

解决方法

你的文件中有has_attached_file:image吗? 如果是,请确保它在validates_attachment之前.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读