0
你好 我是新的RoR。如何將簡單的控制器邏輯切換到模型? 我的數據庫列是ORDER_TYPE,數量,quantity_adjusted從控制器移動代碼到模型(薄控制器胖模型)
控制器
def create
@product = Product.new(params[:product])
# This is the control structure I want to move to Model
if @product.order_type = "Purchase"
@product.quantity_adjusted = -quantity
else
@product.quantity_adjusted = quantity
end
end
型號
class Product < ActiveRecord::Base
end
感謝 LH