I’am working on a project about a booking system for a hotel, i have the Client model and the Reservation model, the client has_many reservations and the reservation belongs_to :client.
The problem si that when i want to create a new reservation, i want to be able to create a client in the same form…
Here is the form:
<%= form_for(@reserva) do |f| %>
<% if @reserva.errors.any? %>
<%= pluralize(@reserva.errors.count, “error”) %> prohibited this reserva from being saved:
The first rule of debugging is always to identify which section is
going wrong. First look log/development.log where you can see the
parameters passed to the controller. If they look right then you can
start debugging the controller to see where the problem is (you can
use puts statements in the controller code to print data, which will
appear in the server terminal window). If the parameters look wrong
then the problem is with the view, so then inspect the html to see if
that is correct, and so on. Keep splitting the problem down so you
identify a smaller and smaller area where the problem may be. As I
said, this is a fundamental technique of debugging.
accepts_nested_attributes_for :clientes, allow_destroy: true
in your model and we should declare wrong think
<%= f.fields_for :cliente do |cliente_builder| %>
not a client, we have has_nany relation then we need declare clients
and your controller need build address object such as
@reserva = Reserva.new
1.times{@reserva.clients.builds}
We should declare worng
cliente = @reserva.build_cliente
actualy this is uesd for has_one relation