使用Carrierwave上传图像并在验证失败时呈现图像。Carrierwave在验证失败后显示图像
场景:
访问用户编辑页面,它包含了用户的头像图片。 上传一个大于4 MB的新头像图片并点击更新。 验证器因文件大小大于4 MB而失败。 用户编辑页面显示正确的错误消息。
问题:
图像显示在呈现编辑页面。如果我重新访问用户编辑页面,它会消失,并且可以确认它没有保存在数据库中。
我也在使用'file_validator
'宝石。
class User < ActiveRecord::Base
...
validates :avatar, file_size: { less_than: 4.megabytes }
...
end
class UsersController < ApplicationController
...
def update
if @user.update_attributes(user_params)
flash[:success] = "Your account settings were successfully updated."
redirect_to @user
else
render 'edit'
end
end
编号:https://github.com/johnTheDudeMan/foodme
我试过了CarrierWave wiki的指令来删除缓存目录,但是验证失败后它们不会被删除。 https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Delete-cache-garbage-directories –