我有谷歌/堆栈溢出了几个小时,没有找到解决这个问题的办法.我想知道我的安装PaperClip是不成功的.我正在验证我的模型文件夹中的图像附件:
validates :image,presence: true,content_type: { content_type: ['image/jpeg','image/jpg','image/png','image/gif']},size: { less_than: 5.megabytes }
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之前.