I have the following models:
我有以下模型:
class MealPlan < ActiveRecord::Base
has_many :food_contents
has_many :foods,:through => :food_contents
accepts_nested_attributes_for :food_contents
attr_accessible :food_contents_attributes,:name
end
class Food < ActiveRecord::Base
validates_presence_of :name,:protein,:carbs,:fats,:calories
validates_numericality_of :protein,:carbs,:fats,:calories
end
class FoodContent < ActiveRecord::Base
belongs_to :meal_plan
belongs_to :food
attr_accessible :food_id, :how_much,:meal_plan_id
validates_presence_of :food,:meal_plan
end
class