2016-04-24 3 views
-4

Я пытался исправить следующую ошибку в течение почти 8 часов:Как я могу исправить ActionController :: ParameterMissing в ReservationsController # create?

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 &nbsp;> 
    <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 &nbsp;> 
    <%= f.text_field :num_seats %><br><br> 
    <label>Number of Guest:</label><p &nbsp;></p> 
    <%= f.text_field :guest_size %><br><br> 
    <label>Reservation Time </label><p &nbsp;> 
    <%= 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 

Сообщение об ошибке:

This is the error message.

+0

@Alfie Я не думаю, что это дублированный вопрос. Причина ошибки отличается. И решения тоже. – psantos

+0

Ошибка совпадает ('ActionController :: ParameterMissing'). Просто имя параметра отличается. – Alfie

+0

Просмотрите комментарии в предоставленном решении, и вы поймете, что – Alfie

ответ

2

Название модели на reservations_params должно быть в единственном числе: params.require(:reservation)...

изменить этот код:

def reservations_params 
    params.require(:reservations).permit(:table_number,:num_seats,:guest_size,:requested_date,:requested_time) 
end 

к:

def reservations_params 
    params.require(:reservation).permit(:table_number,:num_seats,:guest_size,:requested_date,:requested_time) 
end 

Если вы видите список параметров показали в деталях об ошибке , вы увидите, что есть ключ reservation, но не reservations.

+0

ОК. я попробую :)... – Cross

 Смежные вопросы

  • Нет связанных вопросов^_^