0

与えられた

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

インシデントの編集属性と、インシデント.ユーザーやインシデント.コンタクトなどの親の関連付けを編集する方法がわかりません

これは、たとえば次のように機能します。

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

しかし、incident.customer を実行して Customer.all のドロップダウンを取得する方法がわかりません (incident belongs_to :customer)

試すたびにさまざまなエラーが発生します。

4

1 に答える 1

1

私があなたを正しく理解している場合、コントローラーの show アクション、または関連する場所:

@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]] 形式が生成されます。

Customer.pluck(:id, :name) を使用すると言葉が少なくなりますが、それは執筆時点で Edge Rails にのみあります (ガイドへのリンク)。

于 2012-12-22T12:40:50.020 に答える