Started Ingredient#create
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user