2012-09-26 112 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)。