1
0

Started Ingredient#create

This commit is contained in:
cryptogopher
2019-09-14 23:00:31 +02:00
parent faef248449
commit 0dcb13a065
6 changed files with 41 additions and 8 deletions

View File

@@ -4,8 +4,12 @@ class Ingredient < ActiveRecord::Base
}
belongs_to :project
has_many :nutrients
belongs_to :ref_unit, class_name: 'Unit'
has_many :nutrients, inverse_of: :ingredient
accepts_nested_attributes_for :nutrients, allow_destroy: true
#reject_if: proc { |attrs|
# attrs['quantity_id'].blank? && attrs['amount'].blank?
#}
validates :project, associated: true
validates :name, presence: true, uniqueness: {scope: :project_id}

View File

@@ -1,8 +1,10 @@
class Nutrient < ActiveRecord::Base
belongs_to :ingredient
belongs_to :ingredient, inverse_of: :nutrients
belongs_to :quantity
belongs_to :unit
validates :ingredient, presence: true, associated: true
validates :quantity, presence: true, associated: true
validates :quantity, presence: true, associated: true, uniqueness: {scope: :ingredient_id}
validates :amount, numericality: {greater_than: 0}
validates :unit, presence: true, associated: true
end