Skip to content
Browse files

passing the current_user.id to the change_availability method

  • Loading branch information...
1 parent d6fb66a commit 25bb4f1bdd825870d55538f25c161fd22eb29cdb @chaserx chaserx committed Jul 22, 2012
Showing with 8 additions and 6 deletions.
  1. +6 −4 app/controllers/items_controller.rb
  2. +2 −2 app/models/item.rb
View
10 app/controllers/items_controller.rb
@@ -81,14 +81,15 @@ def destroy
end
end
- # TODO(chase): this should probably be one action that changes the state
+ # TODO(chase): This should probably be one action that changes the state
# of the item.
- # also, probably shouldn't redirect, maybe just some ajax.
+ # Also, probably shouldn't redirect, maybe just some ajax.
+ # PUT /items/1/check_in
def check_in
@item = Item.find(params[:id])
if @item.checkedout?
- if @item.change_availability
+ if @item.change_availability(current_user.id)
redirect_to @item, success: 'Item successfully checked in'
else
redirect_to @item, error: 'Item could not be checked in'
@@ -98,10 +99,11 @@ def check_in
end
end
+ # PUT /items/1/check_out
def check_out
@item = Item.find(params[:id])
if @item.checkedin?
- if @item.change_availability
+ if @item.change_availability(current_user.id)
redirect_to @item, success: 'Item successfully checked out'
else
redirect_to @item, error: 'Item could not be checked out'
View
4 app/models/item.rb
@@ -39,12 +39,12 @@ def lookup_by_tag_number(tag)
end
# Changes the checkedin, checkedout status and timestamp.
- def change_availability
+ def change_availability(user_id)
unless self.lost_item?
if self.checkedin?
# change to checkedout
self.update_attributes(checkedout: true, time_checked_in: '',
- checkedin: false, checked_out_by: current_user,
+ checkedin: false, checked_out_by: user_id,
time_checked_out: Time.now)
elsif self.checkedout?
# change to checkedin

0 comments on commit 25bb4f1

Please sign in to comment.
Something went wrong with that request. Please try again.