0
@@ -6,18 +6,21 @@ class Recipe < ActiveRecord::Base
0
belongs_to :food_category
0
validates_presence_of :name
0
validates_associated :ingredients
0
validates_associated :instructions
0
-
after_update :save_instructions
0
+
## after_update :save_instructions
0
after_update :save_ingredients
0
- def new_ingredient_attributes=(ingredient_attributes)
0
- ingredient_attributes.each do |attributes|
0
- ingredients.build(attributes)
0
+ def new_ingredient_attributes=(ingredient_attributes)
0
+ ingredient_attributes.each do |attributes|
0
+ ingredients.build(attributes)
0
def existing_ingredient_attributes=(ingredient_attributes)
0
ingredients.reject(&:new_record?).each do |ingredient|
0
@@ -25,14 +28,62 @@ class Recipe < ActiveRecord::Base
0
ingredient.attributes = attributes
0
- ingredient
.delete(task)
0
+ ingredient
s.delete(ingredient)
0
ingredients.each do |ingredient|
0
+ def existing_ingredient_attributes=(ingredient_attributes)
0
+ ingredients.reject(&:new_record?).each do |ingredient|
0
+ attributes = ingredient_attributes[ingredient.id.to_s]
0
+ ingredient.attributes = attributes
0
+ ingredient.delete(ingredient)
0
+ def new_instruction_attributes=(instruction_attributes)
0
+ instruction_attributes.each do |attributes|
0
+ instructions.build(attributes)
0
+ def existing_instruction_attributes=(instruction_attributes)
0
+ instructions.reject(&:new_record?).each do |instruction|
0
+ attributes = instruction_attributes[instruction.id.to_s]
0
+ instruction.attributes = attributes
0
+ instructions.delete(instruction)
0
+ instructions.each do |instruction|
0
+ instruction.save(false)
0
+ def existing_instruction_attributes=(instruction_attributes)
0
+ instructions.reject(&:new_record?).each do |instruction|
0
+ attributes = instruction_attributes[instruction.id.to_s]
0
+ instruction.attributes = attributes
0
+ instruction.delete(instruction)