0

quoterfq見積もりが作成されたときに既知のテスト項目を取得します( @rfq.test_items)。テーブル quote_test_items には、見積もり ( @quote.quote_test_items) のすべてのテスト項目が格納されます。

quoteモデルには、次のものがあります。

accepts_nested_attributes_for :quote_test_items, :reject_if => proc {|item| item['test_item_id'].blank? }, :allow_destroy => true

すべてのテスト項目をコントローラーrfqに渡して、ユーザーがいくつかのテスト項目を削除したい場合にそれらを表示する必要があります。quote controller で行ったことは次のとおりです。quotenewnew

@rfq.test_items.each do |it|
     @quote.quote_test_items.build
     @quote.quote_test_items << it
end

エラーがあります:

QuoteTestItem(#56736972) expected, got TestItem(#50178372)

controller で次のことを試しましたnew

@quote.test_items << @rfq.test_items

コントローラにエラーは発生しません。ただし、以下のコードのビューにはエラー (未定義のメソッド:test_item_id) があります。

<%= f.fields_for @quote.quote_test_items  do |builder| %>
        <ul>
          <div class="fields">
            <li><%= builder.input :test_item_id, :collection => TestItem.active_test_item.all(:order => 'name'), :label_method => :name, :value_method => :id,
                                  :label => false %><%= link_to_remove_items "remove", f %></li>   
          </div>
        </ul>
    <% end %>

コントローラーでネストされた属性値を渡す正しい方法は何ですか? 助けてくれてありがとう。

4

0 に答える 0