Rails 3 best_in_place编辑嵌套模型

时间:2012-09-26 17:30:47

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

鉴于

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

我无法弄清楚如何在事件和父关联上编辑属性,例如incident.user或incident.contact

这适用于例如:

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

但我无法弄清楚如何做事件。客户下载Customer.all(事件belongs_to:客户)

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

1 个答案:

答案 0 :(得分: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

这会产生[{3}}所需的[[a,b],[c,d]]格式。

使用Customer.pluck(:id,:name)会不那么罗嗦,但在撰写本文时(docs)仅限于Edge Rails。