carrierwave extension_white_list not working

守給你的承諾、 提交于 2019-12-24 11:44:30

问题


here is a similar case but no solution CarrierWave extension_white_list doesn't seem to work Carrierwave provides a function extension_white_list which is supposed to prevent a user from uploading an invalid file. I have uncommented this function but how do I handle this case? I want to catch this error and inform the user that he should change the file.

this wiki entry seems relevant but I'm not sure how to proceed https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-uploads-with-Active-Record


回答1:


According to this issue https://github.com/carrierwaveuploader/carrierwave/issues/1896

The solution is this and it worked for me;

change:

def extension_white_list
end

to:

def extension_whitelist
end

so they have removed the underscore from whitelist word.




回答2:


Inside your model, validates_integrity_of :avatar will cause whitelist violations to act much like validates_presence_of :another_field would with a blank field when saving, i.e. save will return false, after which valid? will be false and there will be a pertinent error message available in user.errors[:avatar].



来源:https://stackoverflow.com/questions/19043926/carrierwave-extension-white-list-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!