Я пытаюсь отобразить различные варианты выбора для пользователей в show.html.erb, когда поставщик выбирает наборы.
Проблема заключается в том, что у поставщика есть несколько вариантов, 1 бутылка, 3бутылок, 6 и 12 бутылок.
My _form.html.erb abstract:
<% if @wine.is_1 == true %>
<%= f.select :bottles, [["1 bottle", "1"]], id: "bottle", prompt: "Select...", class:"form-control" %>
<% end %>
<% if @wine.is_3 == true %>
<%= f.select :bottles, [["3 bottles", "3"]], id: "bottle", prompt: "Select...", class:"form-control" %>
<% end %>
<% if @wine.is_6 == true %>
<%= f.select :bottles, [["6 bottles", "6"]], id: "bottle", prompt: "Select...", class:"form-control" %>
<% end %>
Есть ли какая-либо альтернатива, использующая контроллер резервирования, чтобы сделать код минимальным?И как мне получить общую сумму для оплаты?
Контроллер бронирования
class ReservationsController < ApplicationController
before_action :authenticate_user!
def create
wine = Wine.find(params[:wine_id])
if current_user == wine.user
flash[:alert] = "You cannot book your own wine!"
else
start_date = Date.parse(reservation_params[:start_date])
@reservation = current_user.reservations.build(reservation_params)
@reservation.wine = wine
@reservation.price = wine.price
@reservation.total = wine.price * #bottles
@reservation.save
flash[:notice] = "Booked Successfully!"
end
redirect_to wine
end