-
-
Save go-east/6c06687ecf08424339f134fae499c343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookingsController < ApplicationController | |
before_action :find_parking_spot | |
def index | |
@bookings = Booking.all | |
end | |
def new | |
@booking = Booking.new | |
end | |
def create | |
@booking = @parking_spot.bookings.build(booking_params) | |
@booking.save | |
flash[:notice] = 'Booking created successfully' | |
#redirect to user booking show | |
redirect_to parking_spot_bookings_path | |
end | |
def total_price | |
total_price = find_parking_spot.price | |
end | |
private | |
def find_parking_spot | |
@parking_spot = ParkingSpot.find(params[:parking_spot_id]) | |
end | |
def booking_params | |
params.require(:booking).permit(:start_at, :end_at, total_price: total_price).merge(user: current_user) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Book Now</h1> | |
<h2><%= @parking_spot.street_address %></h2> | |
<p> the price is <%= @booking.total_price %> </p> | |
<%= simple_form_for [@parking_spot, @booking] do |f| %> | |
<%= f.input :start_at %> | |
<%= f.input :end_at %> | |
<%= f.submit %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment