从 Carrierwave 上传器内部访问模型
我正在尝试为我正在开发的 Web 应用程序实现手动裁剪,到目前为止我已经做到了:
version :croppedversion do
process :manualcrop => [model.crop_x, model.crop_y, model.crop_h, model.crop_w]
end
process :resize_to_limit => [600, 600]
def manualcrop(x,y,h,w)
manipulate! do |img|
img = img.crop(x,y,h,w)
end
end
问题是模型显示为零。从我读过的文档来看,这将是正确的方法。
有什么建议吗?我现在已将裁剪调用移至模型中的回调中,但我真的希望它驻留在载波内
I'm trying to implement a manual crop for a web application I'm working on, and I have this so far:
version :croppedversion do
process :manualcrop => [model.crop_x, model.crop_y, model.crop_h, model.crop_w]
end
process :resize_to_limit => [600, 600]
def manualcrop(x,y,h,w)
manipulate! do |img|
img = img.crop(x,y,h,w)
end
end
The problem is that model is turning up as nil. From the documentation I've read this would be the correct way to go about it.
Any suggestions? I've moved the call to cropping into a callback in the model for now, but would really like for it to reside inside carrierwave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题。我有
但忘记将它们包含在 attr_accessible 中的作物变量。通过做
我能够获取模型作物变量。我不知道这是否可以解决您的问题,因为您描述的是返回 nil 的模型而不是裁剪方法。
I ran into a similar issue. I had
but forgot to include them the crop variables in the attr_accessible. By doing
I was able to get the model crop variables. I dont know if this would solve your issue because you're describing the model returning nil rather than the crop methods.
当我尝试访问模型数据时,我的对象在 CarrierWave 中为零,对此我感到非常挣扎。
对我来说,问题出在我的控制器上。这看起来不太适合您的情况,但我正在通过执行以下操作来运行查询: model.user.foo - 如果我在创建对象后立即将此用户分配给模型,它将出现 nil 。
I struggled very much with my object being nil in CarrierWave when trying to access model data.
For me, the issue was in my controller. This doesn't look like it applies too much to your situation, but I was running a query by doing: model.user.foo - It would come up nil if I was immediately assigning this user to the model after creating the object.