2013-09-30 2 views
1

주문과 제품이 있고 orders_products라는 조인 테이블이 order_products를 통해 많은 제품을 가지고 있으며 중첩 된 값을 허용합니다. order_productRuby on Rails의 허용되지 않는 매개 변수가 많음

에 Params

def order_params 
    params.require(:order).permit(:id, :order_number, :customer_id, {order_products_attributes: [:id, :order, :product, :quantity ]}, {:product_ids => []}) 

end 

주문 모델

class Order < ActiveRecord::Base 
    belongs_to :customer 
    has_many :order_products, class_name: "OrderProduct" 
    has_many :products, through: :order_products 
    accepts_nested_attributes_for :order_products, :allow_destroy => true 
end 

주문 제품 모델

:

내가 그것을 저장하려고

는 허가되지 않은 paramters 말을 계속
class OrderProduct < ActiveRecord::Base 
    belongs_to :product 
    belongs_to :order 
end 

순서 제어기 새로운 액션

def new 
    @order = Order.new 
    @order.order_products.build 
end 

주문서

<%= simple_form_for @order do |f| %> 
<%= f.input :order_number %> 

<%= f.fields_for :order_product do |fa| %> 
    <%= fa.input :product, collection: Product.all %> 
    <%= fa.input :quantity %> 

    <% end %> 

<%= f.association :customer, as: :select %> 

<%= f.submit %> 
<% end %> 

에 Params 해시 - { "UTF8"=> "√", "authenticity_token"=> "yBrH91u0OHTSPnCFO/484Ff6CRtyRLSg5AKD1Lc33k4 =", "order"=> { "order_number"=> "0121", "order_product"=> { "product"=> "4" "수량"=> "5"}, "CUSTOMER_ID가"=> "3"}, "커밋"=>}

허가되지 않은 매개 변수 "오더 생성"order_product

답변

1

여기 s 누락을 :

<%= f.fields_for :order_products do |fa| %> 
+0

좋아요, 필자는 허용하지 않은 매개 변수를 얻었습니다. 제품 – user2829533

+0

이제 매개 변수는 어떻게 생깁니 까? –

+0

'제품'이 협회 일 필요가 있을까요? '<% = fa.association : product, as : : select, collection : Product.all %>'. –