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