Paper_trail 与 Accepts_nested_attributes_for
我有一个 Rails 应用程序,其中包含文章,用户可以将链接和评论添加为嵌套属性。
我在 paper_trail https://github.com/airblade/paper_trail/ 文档中看到这不是被那颗宝石覆盖。我将如何设置撤消功能,以便当用户单击撤消时恢复/更新嵌套属性或 has_many 关联?
I have a rails app that has articles that and the user can add links and reviews as nested attributes.
I saw in the paper_trail https://github.com/airblade/paper_trail/ documentation that this is not covered by that gem. How would I go about setting up undo functionality so that nested attributes or has_many associations are restored/updated when a user clicks undo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,如果您将“销毁”帖子挂接到撤消按钮,则在单击撤消时至少会删除链接。基本上,您通过特殊的
_destroy
键传递一个哈希,它将删除嵌套的模型记录。从 Rails 3 文档此处:
现在,当您将 _destroy 键添加到属性哈希,其值为 true,您将销毁关联的模型:
I think if you hook in a "destroy" post to the undo button it will at least remove the links if they click undo. Basically you pass a hash with the special
_destroy
key it will remove the nested model records.From Rails 3 docs here:
Now, when you add the _destroy key to the attributes hash, with a value that evaluates to true, you will destroy the associated model: