Skip to content

Instantly share code, notes, and snippets.

@aakashd
Created May 7, 2013 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakashd/5535265 to your computer and use it in GitHub Desktop.
Save aakashd/5535265 to your computer and use it in GitHub Desktop.
ActiveAdmin multi level has many configuration within Snacker
class NutritionData < ActiveRecord::Base
attr_accessible :calories, :calories_from_fat, :header, :item_id, :serving, :nutrition_items_attributes
validates :calories, :presence => true, :numericality => true
validates :calories_from_fat, :presence => true, :numericality => true
validates :header, :presence => true
validates :serving, :presence => true
belongs_to :item
has_many :nutrition_items
accepts_nested_attributes_for :nutrition_items, :allow_destroy => true
end
class NutritionItem < ActiveRecord::Base
attr_accessible :nutrition_data_id, :title, :value, :child_nutrition_items_attributes
validates :title, :presence => true
validates :value, :presence => true
belongs_to :nutrition_data
belongs_to :parent, :class_name => 'NutritionItem'
has_many :child_nutrition_items, :class_name => 'NutritionItem', :foreign_key => :parent_id
accepts_nested_attributes_for :child_nutrition_items, :allow_destroy => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment