2016-01-12 18:43:00 -06:00
|
|
|
class Recipe < ActiveRecord::Base
|
|
|
|
|
2016-01-13 17:10:43 -06:00
|
|
|
has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
|
|
|
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
2016-01-19 16:50:39 -06:00
|
|
|
belongs_to :user
|
2016-01-13 17:10:43 -06:00
|
|
|
|
2016-01-18 19:41:26 -06:00
|
|
|
scope :active, -> { where('deleted <> ? OR deleted IS NULL', true) }
|
|
|
|
|
2016-01-13 17:10:43 -06:00
|
|
|
accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
|
|
|
|
accepts_nested_attributes_for :recipe_steps, allow_destroy: true
|
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :yields, numericality: true, allow_blank: true
|
|
|
|
validates :total_time, numericality: true, allow_blank: true
|
|
|
|
validates :active_time, numericality: true, allow_blank: true
|
|
|
|
|
2016-01-18 19:41:26 -06:00
|
|
|
def scale(factor)
|
|
|
|
recipe_ingredients.each do |ri|
|
|
|
|
ri.scale(factor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-12 18:43:00 -06:00
|
|
|
|
|
|
|
end
|