I have the followings:
routes.rb
Rails.application.routes.draw do
devise_for :users
resource :user, only: [] do
# this will route /user/bookings to Users::BookingsController
resources :bookings, only: [:index], module: :users
end
resources :spaces, only: [:index, :new, :create, :show] do
# shallow: true will prevent the member routes from being nested
# it will also prevent resources :payments from being nested in `/spaces/`
resources :bookings, shallow: true do
resources :payments, only: :new, shallow: true
end
end
root to: 'pages#home'
get 'about', to: 'pages#about'
get 'bookings/:id/payments/success', to: 'payments#success', as: :success
mount StripeEvent::Engine, at: '/stripe-webhooks'
end
payments_controller.rb
class PaymentsController < ApplicationController
def new
@booking = current_user.bookings.find(params[:booking_id])
@days = 1 + (@booking.check_out - @booking.check_in).to_i
@service_fee = @booking.space.price * @days * 0.15
@total_price = (@booking.space.price * @days) + @service_fee
end
def success
@booking = current_user.bookings.find(params[:id])
end
end
I am wondering why in #new I have to retrieve @booking using params[:booking_id] instead of params[:id].