为什么我无法在 Carrierwave 中编辑此图像?
我有两个 Mongoid 模型:Store 和 Product。他们的关系是一个Store has_many Products,并且Products owns_to Store。每个模型都有一些可以使用 Carrierwave 附加的图像,如下所示:
mount_uploader :logo, ImageUploader
我可以添加和编辑 Store 模型中的图像。但在产品中,我只能在创建产品时添加图像,而不能在编辑产品时添加图像。这似乎是一个 deep_copy 问题,类似于在 Mongoid 中如果你有一个名为 urls 的数组并且想要更新该数组,则必须调用
urls_will_change!
所以我尝试在 before_update 回调中调用等效方法(logo_will_change!),但它没有做任何事情。我应该在其他地方这样做还是这是另一个问题?
I have two Mongoid models, Store and Product. Their relationship is that a Store has_many Products, and Products belongs_to Store. Each of these models has some images that can be attached using Carrierwave, that look like this:
mount_uploader :logo, ImageUploader
I am able to add and edit images that are in the Store model. But in Product I can only add an image on creation off a Product, but not with editing a product. This seems somehow to be a deep_copy issue, similar to how in Mongoid if you have an array called urls and you want to update that array, you must call
urls_will_change!
So I have tried calling the equivalent method (logo_will_change!) inside of a before_update callback, but it doesn't do anything. Is there somewhere else I should be doing this or is it another problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码对我有用,所以可能还有其他事情发生:
The code below worked for me, so there may be something else going on: