Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding more to the check in / out actions

  • Loading branch information...
commit bd1ab776844ce3172339d47f49b8e9a833543afd 1 parent 24bc496
@chaserx chaserx authored
Showing with 28 additions and 3 deletions.
  1. +22 −2 app/controllers/items_controller.rb
  2. +6 −1 config/routes.rb
View
24 app/controllers/items_controller.rb
@@ -82,10 +82,30 @@ def destroy
end
def check_in
- #
+ @item = Item.find(params[:id])
+ if @item.checkedout?
+ if @item.update_attributes(checkedout: false, time_checked_in: Time.now,
+ checkedin: true, checked_out_by: '',
+ time_checked_out: nil)
+ else
+ redirect_to @item, error: 'Item could not be checked in'
+ end
+ else
+ redirect_to @item, error: 'Item is not checked out'
+ end
end
def check_out
- #
+ @item = Item.find(params[:id])
+ if @item.checkedin?
+ if @item.update_attributes(checkedout: true, time_checked_in: '',
+ checkedin: false, checked_out_by: current_user,
+ time_checked_out: Time.now)
+ else
+ redirect_to @item, error: 'Item could not be checked out'
+ end
+ else
+ redirect_to @item, error: 'Item is not checked in'
+ end
end
end
View
7 config/routes.rb
@@ -1,5 +1,10 @@
Collector::Application.routes.draw do
- resources :items
+ resources :items do
+ member do
+ put :check_in
+ put :check_out
+ end
+ end
devise_for :users
Please sign in to comment.
Something went wrong with that request. Please try again.