-4
我一直在試圖解決以下錯誤幾乎8小時以上如何在ReservationsController#create中修復ActionController :: ParameterMissing?
Param is missing or the value is empty: reservations
Application Trace | Framework Trace | Full Trace
app/controllers/reservations_controller.rb:18:in `reservations_params'
app/controllers/reservations_controller.rb:11:in `create'
有人可以幫我解決這個問題?我的代碼如下。
new.html.rb
源:
<%= form_for @reservations do |f| %>
<%= f.label :table_number %><p >
<select name="table_number">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select><br><br>
<label>Number of Seats:</label><p >
<%= f.text_field :num_seats %><br><br>
<label>Number of Guest:</label><p ></p>
<%= f.text_field :guest_size %><br><br>
<label>Reservation Time </label><p >
<%= f.time_select :requested_time %><br><br> <!-- ,{ampm: true} -->
<%= f.submit class: "rc_btn_02" %><br><br>
<% end %>
reservations_controller.rb
源:
def index
@reservations = Reservation.new
end
def new
@reservations = Reservation.new
end
def create
@reservations = Reservation.new(reservations_params)
@reservations.save
redirect_to @reservations
end
def reservations_params
params.require(:reservations).permit(:table_number,:num_seats,:guest_size,:requested_date,:requested_time)
end
錯誤消息:
@Alfie我不認爲這是一個重複的問題。錯誤的原因是不同的。還有解決方案。 – psantos
錯誤是一樣的('ActionController :: ParameterMissing')。只是參數名稱不同。 – Alfie
查看提供的解決方案中的評論,你會明白 – Alfie