Preliminary MealsController#create
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
class Ingredient < ActiveRecord::Base
|
||||
belongs_to :composition, inverse_of: :ingredients, required: true
|
||||
belongs_to :composition, inverse_of: :ingredients, polymorphic: true, required: true
|
||||
belongs_to :food, required: true
|
||||
belongs_to :part_of, required: false
|
||||
|
||||
validates :ready_ratio, numericality: {greater_than_or_equal_to: 0.0}
|
||||
validates :amount, numericality: {greater_than_or_equal_to: 0.0}
|
||||
|
||||
after_initialize do
|
||||
if new_record?
|
||||
self.ready_ratio ||= BigDecimal.new('1.0')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class Meal < ActiveRecord::Base
|
||||
belongs_to :project, required: true
|
||||
|
||||
has_many :ingredients, as: :composition, dependent: :destroy, validate: true
|
||||
has_many :ingredients, as: :composition, inverse_of: :composition, dependent: :destroy,
|
||||
validate: true
|
||||
has_many :foods, through: :ingredients
|
||||
validates :ingredients, presence: true
|
||||
accepts_nested_attributes_for :ingredients, allow_destroy: true, reject_if: proc { |attrs|
|
||||
|
||||
Reference in New Issue
Block a user