typeerror - ActionController “No explicit conversion of Symbol into Integer” for new record in Rails 4.2.1 -
i'm trying create @booking
, @booking.build_passenger
in form_for
nested attributes in rails 4.2.1
as see in console @ bottom of image:
1. params.require(:booking)
returns hash-like params @booking
2. params.class
returns actioncontroller::parameters
as params
seems behave correctly, imo problem hides somewhere in form:
<%= form_for @booking |f| %> <%= f.hidden_field :flight_id, value: params[:flight_id] %> <%= render 'flights/flight_info' %> <div class="field"> <b><%= f.label :num_tickets, "tickets" %></b> <%= f.select(:num_tickets, @num_tickets) %> </div><br> <h4>passenger info:</h4> <%= f.fields_for @booking.build_passenger |pass| %> <div class="field"> <%= pass.label :name %> <%= pass.text_field :name %> </div> <div class="field"> <%= pass.label :email %> <%= pass.email_field :email %> </div> <% end %> <%= f.submit 'book flight!' %> <% end %>
booking model:
class booking < activerecord::base belongs_to :flight belongs_to :passenger accepts_nested_attributes_for :passenger end
question: , how have edit code app start creating @booking
instances + @booking.build_passenger()
your booking_params
needs like:
def booking_params params.require(:booking).permit(:flight_id, :num_tickets, passenger_attributes: [:id, :name, :email]) end
Comments
Post a Comment