Skip to content

Commit

Permalink
booking implemented with my_bookings section
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-H-D committed Nov 26, 2020
1 parent 150fe6b commit b3b858a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
19 changes: 12 additions & 7 deletions app/controllers/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ def new
end

def create
@booking = Booking.new
@booking = Booking.new(booking_params)
@studio = Studio.find(params[:studio_id])
@booking.studio = @studio
@booking.total_price = (@booking.checkout-@booking.checkin).to_int * @studio.price
@booking.user = current_user
@booking.save
redirect_to studios_path
redirect_to my_bookings_path
end

def destroy
def booking_manager
# binding.pry
@bookings = Booking.where(user: current_user)
@studios = Studio.where(user: current_user)
end

# private
private

# def booking_params
# params.require(:booking).permit(:checkin, :checkout)
# end
def booking_params
params.require(:booking).permit(:checkin, :checkout)
end
end
1 change: 0 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ class PagesController < ApplicationController

def home
end

end
14 changes: 14 additions & 0 deletions app/views/bookings/booking_manager.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1>my bookings</h1>

<div class="list-bookings">
<ul>
<% @bookings.each do |booking| %>
<h2> <li>Studio : <%= booking.studio.title %></li></h2>
<h3><li>Check-in : <%= booking.checkin %></li></h3>
<h3><li>Check-out : <%= booking.checkout %></li></h3>
<h3><li>Studio Address : <%= booking.studio.address %></li></h3>
<h3><li>Daily Price : <%= booking.studio.price %>Chf</li></h3>
<h2><li>Total Price : <%= booking.total_price %>Chf</li></h2>
<% end %>
</ul>
</div>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
root to: 'pages#home'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
resources :studios, only:[:index, :show, :new, :create] do
resources :bookings, only:[:index, :new, :create]
resources :bookings, only:[:new, :create]
end
resources :bookings, only:[:destroy]
get "/my_bookings", to: "bookings#booking_manager"
end

0 comments on commit b3b858a

Please sign in to comment.