Skip to content

Commit

Permalink
added the functionality for owner to Update/delete booking customzi…
Browse files Browse the repository at this point in the history
…ed the show boat page in function of who is viewing it
  • Loading branch information
Sikaopa committed Jun 2, 2022
1 parent 7c97b83 commit f4ff3ca
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
18 changes: 18 additions & 0 deletions app/controllers/boats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 26,27 @@ def create
end
end

def edit
@boat = Boat.find(params[:id])
end

def update
@boat = Boat.find(params[:id])
@boat.update(boat_params)
redirect_to boat_path(@boat)
end

def destroy
@boat = Boat.find(params[:id])
@boat.destroy
redirect_to boats_path, status: :see_other
end


private

def boat_params
params.require(:boat).permit(:make, :location, :image_url, :capacity, :color, :daily_rate)
end

end
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
class UsersController < ApplicationController
def show
end

end
2 changes: 1 addition & 1 deletion app/models/boat.rb
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
class Boat < ApplicationRecord
belongs_to :user
has_many :bookings
has_many :bookings, dependent: :destroy
end
21 changes: 21 additions & 0 deletions app/views/boats/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
<div class="container">
<div class="text-center">
<h1>Edit Boat: <%=@boat.make%></h1>
</div>


<div class = "row mt-5">
<div class="col-sm-12 col-md-6 mx-auto">
<%= simple_form_for(@boat) do |f| %>
<%= f.input :make %>
<%= f.input :capacity %>
<%= f.input :color %>
<%= f.input :location %>
<%= f.input :daily_rate %>
<%= f.input :image_url %>
<%= f.button :submit, class:"btn btn-primary mt-3 text-center" %>
<% end %>
<hr>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/boats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,8 @@
<p><strong>Make:</strong> <%= boat.make %></p>
<p class="card-text">Capacity: <%= boat.capacity %>
<p>Location: <%= boat.location %> City</p>
<a class="card-text stretched-link" href="#"><strong>$<%= boat.daily_rate %></strong></a>
<a class="card-text stretched-link" href="">Daily rate: <strong>$<%= boat.daily_rate %></strong></a>
<ul><i><%= link_to "See boat", boat_path(boat.id), class: 'btn btn-dark btn-sm border my-2'%></i></ul>
</div>
</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions app/views/boats/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,6 @@
<div class = "picture">
<img src="<%= @boat.image_url %>">
</div>




<div class="card" style="width: 50rem;">
<div class="card-body">
<h5 class="card-title"><strong>Make: <%= @boat.make %></strong></h5>
Expand All @@ -15,7 11,13 @@
<h6 class="card-subtitle my-3 "><strong>Rate: $<%= @boat.daily_rate %></strong></h6>
<p class="card-text">This boat is beautiful and good for all get away and parties</p>
<div class = "text-center d-grid gap-2 mt-5">
<%if current_user != @boat.user%>
<%= link_to "Book it", new_boat_booking_path(@boat), class: "btn btn-dark"%>
<%end%>
<%if current_user == @boat.user%>
<%= link_to "Edit listing", edit_boat_path(@boat), class: 'btn btn-light btn-sm border'%>
<%= link_to "Delete Boat", boat_path(@boat), class: 'btn btn-light btn-sm border', data: {turbo_method: :delete, turbo_confirm: "Delete #{@boat.make}?"}%>
<%end%>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@
devise_for :users
resources :users
root to: "pages#home"
resources :boats, only: [:index,:new, :create, :show] do
resources :boats do
resources :bookings, only:[:new,:create, :update]
get '/booking/:id', to: 'bookings#destroy', as: :delete_booking
end
Expand Down

0 comments on commit f4ff3ca

Please sign in to comment.