在链接表上 CRUD 额外属性的正确 Rails 方法

发布于 2025-01-06 18:04:11 字数 282 浏览 2 评论 0原文

我的多对多链接表上有一个额外的 position 属性。其目的是定义 GroupItem 的手动排序位置。该链接模型称为 ItemGroupMembership

我允许用户在 Backbone 应用程序中通过 jQuery UI 可排序来编辑它。

更新此属性的正确方法是什么?我是否将链接表视为常规模型并拥有 item_group_memberships_controller

I have an extra position attribute on my many-to-many link table. Its purpose is to define hand-ordered position of an Item in a Group. The link model is called ItemGroupMembership.

I am allowing the user to edit this by jQuery UI sortables in a Backbone application.

What is the correct way to update this attribute. Do I treat the link table like a regular model and have a item_group_memberships_controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉怎暖 2025-01-13 18:04:11

首先,项目是如何分配给组的?
这应该在 item_group_memberships_controller 中完成。

所以,

class ItemGroupMembershipsController < Applicationontroller

 def create
   #create the relationship, passing in :position
 end

 def update
    #update the relationship by updating position 
 end

end

How are Item's assigned to Groups in the first place?
This should be done in the item_group_memberships_controller.

So,

class ItemGroupMembershipsController < Applicationontroller

 def create
   #create the relationship, passing in :position
 end

 def update
    #update the relationship by updating position 
 end

end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文