Skip to content

Instantly share code, notes, and snippets.

@go-east
Last active August 17, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save go-east/6c06687ecf08424339f134fae499c343 to your computer and use it in GitHub Desktop.
Save go-east/6c06687ecf08424339f134fae499c343 to your computer and use it in GitHub Desktop.
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
<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