2012-09-26 110 views
0

鑑於的Rails 3 best_in_place編輯嵌套模式

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

我想不出編輯的事件和家長協會,如incident.user或incident.contact

這適用於如何到位屬性例如:

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

但我想不出怎麼辦incident.customer得到下降Customer.all下來(事件belongs_to的:客戶)

我嘗試每種方法都會遇到各種錯誤。

回答

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 

這將產生[[A,B],[C ,d]]格式,docs說是必要的。

Customer.pluck(:id,:name)會稍微羅嗦,但在撰寫本文時只有Edge Rails(link to guides)。