Skip to content

Instantly share code, notes, and snippets.

@ryanfitz
Created January 31, 2011 16:51
Show Gist options
  • Save ryanfitz/804349 to your computer and use it in GitHub Desktop.
Save ryanfitz/804349 to your computer and use it in GitHub Desktop.
class Routine
include Mongoid::Document
field :name, :type => String
field :description, :type => String
embeds_many :workouts
accepts_nested_attributes_for :workouts, :allow_destroy => true
end
class Workout
include Mongoid::Document
field :title, :type => String
field :notes, :type => String
references_many :workout_sets
embedded_in :routine, :inverse_of => :workouts
accepts_nested_attributes_for :workout_sets, :allow_destroy => true
end
class WorkoutSet
include Mongoid::Document
field :reps, :type => Integer
field :sets, :type => Integer
referenced_in :workout
referenced_in :exercise
end
{"routine"=>{"name"=>"another workout", "description"=>"good workout", "workouts_attributes"=>{"0"=>{"title"=>"day1", "notes"=>"asdf", "_destroy"=>"false", "workout_sets_attributes"=>{"0"=>{"_destroy"=>"false", "exercise_id"=>"4d2698a83c850c399a000001", "sets"=>"2", "reps"=>"3"}}}}}, "utf8"=>"✓", "authenticity_token"=>"tpptQ9A7nnfU8lr65RhDtMBQ4HmEHtZm0g6i3XAKfMQ=", "id"=>"4d46db123c850c378f000001"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment