我尝试创建一个 HBTM 关联并在创建订单时创建记录,如下所示:
订单控制器:
def create
@order = Order.create(params[:order])
@order.adresses.new(:order_id => params[:id],:adress_id => params[:adress_id])
if @order.save
redirect_to orders_path,:notice => "Compra criada com sucesso !"
else
redirect_to orders_path,:notice => "Compra nao criada com sucesso cheque os erros e tente novamente !"
end
end
在我的订单模型和我的地址模型中:
order.rb
has_and_belongs_to_many :adresses
adress.rb
has_and_belongs_to_many :orders
对,但我创建了一个模型并收到此错误:
Can't mass-assign protected attributes: adress_id, order_id
所以我创建了模型 adresses_orders.rb :
attr_accessible :order_id,:adress_id
但错误连续我不明白,因为什么
Can't mass-assign protected attributes: adress_id, order_id