Skip to content

Commit

Permalink
completed pundit apart from destroy and update
Browse files Browse the repository at this point in the history
  • Loading branch information
dovet1 committed May 17, 2019
1 parent 17f572c commit 7ff70c1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/controllers/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ def index

def show
@booking = Booking.find(params[:id])
authorize @booking
end

def new
@booking = Booking.new
@vehicle = Vehicle.find(params[:vehicle_id])
authorize @booking
end

def create
@booking = Booking.new(booking_params)
@vehicle = Vehicle.find(params[:vehicle_id])
@booking.vehicle = @vehicle
@booking.renter = current_user
authorize @booking
@booking.save
redirect_to booking_path(@booking)
end
Expand Down
19 changes: 19 additions & 0 deletions app/policies/booking_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class BookingPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end

def new?
true
end

def create?
true
end

def show?
true
end
end
6 changes: 5 additions & 1 deletion app/policies/vehicle_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ class Scope < Scope
def resolve
scope.all
end
end

def show?
true
end

def create?
true
Expand All @@ -12,5 +17,4 @@ def update?
true
end

end
end
2 changes: 1 addition & 1 deletion app/views/vehicles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= f.input :price_per_night %>
<%= f.input :category, collection: ["Campervan", "Caravan", "Trailer Tent", "Motorhome"] %>
<%= f.input :description %>
<%= f.imput :photo %>
<%= f.input :photo %>
<%= f.input :photo_cache, as: :hidden %>
<%= f.submit "Add Vehicle", class: "btn btn-primary" %>
<% end %>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions test/policies/booking_policy_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'test_helper'

class BookingPolicyTest < ActiveSupport::TestCase
def test_scope
end

def test_show
end

def test_create
end

def test_update
end

def test_destroy
end
end

0 comments on commit 7ff70c1

Please sign in to comment.