0
我需要將陣列保存到我的order.rb
模型中。導軌4不允許的參數:產品
數組是:params[:products]
數組是給我這樣的事情:
[{"'name'"=>"31 DVIE33N - Traditional ", "'id'"=>"2", "'quantity'"=>"1", "'accessory'"=>{"'id'"=>"7", "'name'"=>"31-SK4BLANKD-2"}}]
創建行動:
def create
@order = Order.new(order_params)
respond_to do |format|
if @order.save
format.html { redirect_to admin_orders_path(@order), notice: 'Order was successfully created.' }
format.json { render :show, status: :created, location: @order }
else
format.html { render :new }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
我的訂單PARAMS。
private
def order_params
params.permit({:products=>[], products:[])
end
我想兩種不同的方式permite的產品,這就是爲什麼你會看到上面
兩個數組請大家看看,我沒有使用somethig,如:
params.require(:order).permit(:products => []}, :products=>[])
,因爲如果我用我的錯誤:
ActionController::ParameterMissing - param is missing or the value is empty: order:
謝謝。
嗨@Leantraxxx,我加入了relathionship訂購模式。 我不明白「products_attributes」,爲什麼我需要把它放到「products_controller」中。對不起這部分,但我不明白。 「:listing」,「product_attributes:[]」 謝謝 –
其實。如果我在我的「orders_controller」中使用:params.require,我得到錯誤:ActionController :: ParameterMissing - param丟失或值爲空:order: –
對不起'orders_controller' – Leantraxxx