ruby-on-rails – 轨道载波安装条件
发布时间:2020-12-17 02:04:09 所属栏目:百科 来源:网络整理
导读:我需要在一些验证功能后安装图片上传器. 但是,如果我像往常一样在模型中调用uploader: mount_uploader :content,ContentUploader 载波首先下载内容,然后Rails开始验证模型. 具体来说,我根本不想加载大文件!我想检查http标头内容长度和内容类型,然后,如果没
我需要在一些验证功能后安装图片上传器.
但是,如果我像往常一样在模型中调用uploader: mount_uploader :content,ContentUploader 载波首先下载内容,然后Rails开始验证模型. 具体来说,我根本不想加载大文件!我想检查http标头内容长度和内容类型,然后,如果没有问题,请安装上传器. 也许是这样的: if condition mount_uploader :content,ContentUploader end 我该怎么做? 附: Rails版本3.2.12 解决方法
如果您只是想避免加载大文件,这不是要走的路!也就是说,可以有条件挂载覆盖内容=.
作为CarrierWave v1.1.0,仍然没有条件安装.但请注意,mount_uploader在类中首先是includes a module,然后是overrides原始内容=在包含的模块中调用方法content = defined.因此,解决方法只是在调用mount_uploader后重新定义访问器: class YourModel < ActiveRecord::Base mount_uploader :content,ContentUploader def content=(arg) if condition super else # original behavior write_attribute(:content,arg) end end def content # some logic here end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |