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

ruby-on-rails – 如何使用dragonfly调整before_save的图像大小

发布时间:2020-12-17 03:02:41 所属栏目:百科 来源:网络整理
导读:在我的模型中,我有: attr_accessible :photoimage_accessor :photobefore_save :resize_imagedef resize_image self.photo = self.photo.process(:resize,'40x40')end 但保存后,它会从数据库中的记录中删除我的photo_uid(或者根本不写photo_uid) 解决方法
在我的模型中,我有:

attr_accessible :photo
image_accessor :photo
before_save :resize_image

def resize_image
  self.photo = self.photo.process(:resize,'40x40')
end

但保存后,它会从数据库中的记录中删除我的photo_uid(或者根本不写photo_uid)

解决方法

呵呵,我发现:

image_accessor :photo do
   after_assign :resize_image
end

def resize_image
   photo.process!(:resize,'1000x650>')
end

(编辑:李大同)

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

    推荐文章
      热点阅读