안녕하세요 저는 RoR을 신설했습니다. 어떻게 간단한 컨트롤러 로직을 모델로 전환 할 수 있습니까? 내 데이터베이스 열 ORDER_TYPE, 수량,컨트롤러에서 모델로 코드 이동 (씬 컨트롤러 지방 모델)
컨트롤러
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
감사를 할 수있는 여러 가지 방법이 있습니다