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.

Revisions

  1. @invalid-email-address Anonymous created this gist Jun 21, 2012.
    3 changes: 3 additions & 0 deletions appointment.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    belongs_to :reservation
    belongs_to :user
    attr_accessible :reservation_id, :user_id
    2 changes: 2 additions & 0 deletions reservation.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    has_many :appointments
    has_many :users, :through => :appointments
    14 changes: 14 additions & 0 deletions reservation_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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
    3 changes: 3 additions & 0 deletions user.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@

    has_many :appointments
    has_many :reservations, :through => :appointments