我试图使属性等于预定值,而且我不确定是否可以高效地使用以下(在我的订单控制器中) :Ruby on Rails:在控制器(或可能是模型)中等价物品
def create
@order = Order.find(params[:id])
@order.price = 5.99
@order.representative = Product.find(params[:product_id]).representative
@order.shipping_location = SHIPPING_LOCATION
@order.user = current_user
respond_to do |format|
...
end
end
有没有一种更有效的方法来在Rails(也许使用模型)中等同属性?如果我使用两个不同的控制器,是否重复上面为新控制器所做的操作?