Created
June 21, 2012 03:15
-
-
Save tomciopp/2963596 to your computer and use it in GitHub Desktop.
Modeling a reservation system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :reservation | |
belongs_to :user | |
attr_accessible :reservation_id, :user_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_many :appointments | |
has_many :users, :through => :appointments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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