【问题标题】:Correct Rails way to CRUD extra attributes on link table正确的 Rails 方法来 CRUD 链接表上的额外属性
【发布时间】:2012-02-19 22:09:04
【问题描述】:

我的多对多链接表上有一个额外的position 属性。其目的是在Group 中定义Item 的手动位置。链接模型称为ItemGroupMembership

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

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 activerecord many-to-many nested-attributes


    【解决方案1】:

    首先如何将项目分配给组? 这应该在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
    

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多