调用 Object#destroy 时 CarrierWave 不会删除资产?
我在 Rails3 应用程序中使用 CarrierWave 来上传资源。上传方面一切都很好,但是当调用 destroy 方法时,相应的资产不会被删除。
看起来 CarrierWave 为此创建了动态方法,可以在 destroy 方法中使用,因此如果模型是 avatar,那么像 remove_avatar
这样的方法就会出现。
但是,我无法让其中任何一个发挥作用。非常感谢任何提示。
I'm using CarrierWave in a Rails3 app to upload assets. All good on the upload side, but when the destroy method is invoked, the corresponding asset is not removed.
It looks like CarrierWave creates dynamic methods for this that one can use in the destroy method so if the model is avatar
then methods like remove_avatar
spring into existence.
However, I can't get any of that to work. Any hints much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很抱歉回答我自己的问题,但就我而言,这是一个忽略显而易见的简单情况:CarrierWave 模型需要一个字符串字段来包含路径名。所以我的模型是:
正确的迁移是:
咒语中缺少的部分是我的迁移中缺少“资产”字符串。我想我只是没有看到文件中的要求,尽管明智的做法会让它立即变得显而易见。
I'm sorry to answer my own question, but in my case, it was a simple case of overlooking the obvious: The CarrierWave model needed a string field to contain the path name. So my model is:
and the correct migration was:
The missing part of the incantation was that the "asset" string was missing in my migration. I guess I was just not seeing the requirement in the documents although good sense would have made it immediately obvious.
前几天我遇到了同样的问题。它适用于简单的表单,但似乎不喜欢嵌套表单上的 *remove_model_name* 。
最后我只是吸收它并使用了一个隐藏字段和 :_destroy
供参考: https://github.com/galaxylord /rierwave_nested
I ran into the same problem the other day. It worked with a simple form, but didn't seem to enjoy the *remove_model_name* on nested forms.
In the end I just sucked it up and used a hidden_field with :_destroy
For reference: https://github.com/galaxylord/carrierwave_nested