diff --git a/app/models/scissor_lift.rb b/app/models/scissor_lift.rb index 2efdff6d..3f5613e3 100644 --- a/app/models/scissor_lift.rb +++ b/app/models/scissor_lift.rb @@ -8,6 +8,8 @@ class ScissorLift < ApplicationRecord has_one :organization, through: :scissor_lift_checkouts scope :ordered_by_name, -> { order(name: :asc) } + scope :checked_out, -> { joins(:scissor_lift_checkouts).merge(ScissorLiftCheckout.current).distinct } + scope :checked_in, -> { where.not(id: checked_out.select(:id)) } def link scissor_lift_path(self) diff --git a/app/views/scissor_lifts/checkouts/_checkin_form.html.erb b/app/views/scissor_lifts/checkouts/_checkin_form.html.erb index c3d94da4..27f75189 100644 --- a/app/views/scissor_lifts/checkouts/_checkin_form.html.erb +++ b/app/views/scissor_lifts/checkouts/_checkin_form.html.erb @@ -2,8 +2,8 @@ <%= form_with url: checkin_scissor_lifts_path do |f| %> <%= hidden_field_tag 'url', request.original_fullpath %> <%= f.label "Scissor Lift" %> - <%= f.collection_select(:name, ScissorLift.all.ordered_by_name, :name, :name, {prompt: 'Select Scissor Lift...'}) %> + <%= f.collection_select(:name, ScissorLift.checked_out.ordered_by_name, :name, :name, {prompt: 'Select Scissor Lift...'}) %> <%= f.check_box :checkin_type, {style: 'margin-bottom: 2em'} %> <%= f.label :checkin_type, "Used the scissor lift without a green wristband?" %> <%= f.submit 'Checkin', class: 'btn btn-wide'%> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/scissor_lifts/checkouts/_checkout_form.html.erb b/app/views/scissor_lifts/checkouts/_checkout_form.html.erb index bbbad378..82a3da53 100644 --- a/app/views/scissor_lifts/checkouts/_checkout_form.html.erb +++ b/app/views/scissor_lifts/checkouts/_checkout_form.html.erb @@ -13,7 +13,7 @@ <%= form_with url: add_scissor_lifts_path do |f| %> <%= hidden_field_tag 'url', request.original_fullpath %> - <%= f.collection_select(:name, ScissorLift.all.ordered_by_name, :name, :name, {prompt: 'Add Scissor Lift...'}, onchange: 'this.form.submit()') %> + <%= f.collection_select(:name, ScissorLift.checked_in.ordered_by_name, :name, :name, {prompt: 'Add Scissor Lift...'}, onchange: 'this.form.submit()') %> <% end %>

The Borrower

diff --git a/app/views/scissor_lifts/checkouts/_renew_form.html.erb b/app/views/scissor_lifts/checkouts/_renew_form.html.erb index 212bbc96..1866fb81 100644 --- a/app/views/scissor_lifts/checkouts/_renew_form.html.erb +++ b/app/views/scissor_lifts/checkouts/_renew_form.html.erb @@ -2,8 +2,8 @@ <%= form_with url: renew_scissor_lifts_path do |f| %> <%= hidden_field_tag 'url', request.original_fullpath %> <%= f.label "Scissor Lift" %> - <%= f.collection_select(:name, ScissorLift.all.ordered_by_name, :name, :name, {prompt: 'Select Scissor Lift...'}) %> + <%= f.collection_select(:name, ScissorLift.checked_out.ordered_by_name, :name, :name, {prompt: 'Select Scissor Lift...'}) %> <%= f.label "How many hours?" %> <%= f.number_field(:duration, value: '2', min: 0, style: 'margin-bottom: 2em') %> <%= f.submit 'Renew', class: 'btn btn-wide'%> -<% end %> \ No newline at end of file +<% end %>