Skip to content

Instantly share code, notes, and snippets.

@tomciopp
Created June 21, 2012 03:15
Show Gist options
  • Save tomciopp/2963596 to your computer and use it in GitHub Desktop.
Save tomciopp/2963596 to your computer and use it in GitHub Desktop.
Modeling a reservation system
belongs_to :reservation
belongs_to :user
attr_accessible :reservation_id, :user_id
has_many :appointments
has_many :users, :through => :appointments
def create
# When I create a reservation I should have two users added to the appointments table
# the creator of a task, and the person whose bid the creator accepted.
@reservation = @task.build_reservation(...)
@creator = @task.user
@bidder = @reservation.bid.user
if @reservation.save
#should I just rewrite the save method as something else like save_and_make_appointments, and offload this to the model.
redirect_to @task
else
flash[:notice] = "you have broken something"
redirect_to root_path
end
end
has_many :appointments
has_many :reservations, :through => :appointments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment