【问题标题】:Rails 3 best_in_place Edit Nested ModelRails 3 best_in_place 编辑嵌套模型
【发布时间】:2023-03-13 08:05:01
【问题描述】:

给定

<% @incidents.each_with_index do |incident,i| %>

我不知道如何在事件和父关联(例如 event.user 或 event.contact)上设置编辑属性

这适用于例如:

best_in_place incident, :notes, type: :input,  nil: 'Add Note'

但我不知道如何做 event.customer 来获取 Customer.all 的下拉列表(事件 belongs_to :customer)

我每次尝试都会遇到各种错误。

【问题讨论】:

    标签: ruby-on-rails best-in-place inplace-editing


    【解决方案1】:

    如果我对您的理解正确,请在您的控制器的显示操作中或任何相关的地方:

    @customer = Customer.all.map { |c| [c.id, c.customer_name] } # or whatever the customer name attribute is
    

    在你看来:

    = best_in_place incident, :notes,  :type => :select, :collection => @customer
    

    这会产生需要docs 说的 [[a,b], [c,d]] 格式。

    Customer.pluck(:id, :name) 不会那么啰嗦,但这只是在撰写本文时 Edge Rails (link to guides)。

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      • 2016-06-02
      • 2011-07-09
      相关资源
      最近更新 更多