Skip to content

Instantly share code, notes, and snippets.

@tomelm
Created June 12, 2013 02:17
Show Gist options
  • Save tomelm/5762380 to your computer and use it in GitHub Desktop.
Save tomelm/5762380 to your computer and use it in GitHub Desktop.
class Appointment < ActiveRecord::Base
has_many :steps
has_many :roles, through: :steps
has_many :events, through: :roles
end
class Event < ActiveRecord::Base
belongs_to :role
# access appointment by doing event.role.step.appointment
end
class Role < ActiveRecord::Base
has_many :events
belongs_to :step
# access appointment by doing role.step.appointment
end
# /appointments/
# /appointments/1/
# /appointments/new
resources :appointments do
# /steps/1
# /appointments/1/steps/new
# /steps/1/edit
resources :steps, shallow: true do
# /steps/1/roles/new
# /roles/1/edit
# /roles/1
resources :roles, shallow: true do
# /roles/1/events/new
# /roles/1/events/
# /events/1
# /events/1/edit
resources :events, shallow: true
end
end
end
class Step < ActiveRecord::Base
has_many :roles
has_many :events, through: :roles
belongs_to :appointment
#access appointment by doing step.appointment
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment