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? %>
<div id="error_explanation">
<h2><%= pluralize(@reserva.errors.count,
"error") %>
prohibited this reserva from being saved:</h2>
<ul>
<% @reserva.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="span12 field-box">
<%= f.label :cliente_id %>
<% clientes_array = Cliente.all.map { |cliente|
["#{cliente.nombre} #{cliente.apellido}", cliente.id] } %>
<%= f.select(:cliente_id,
options_for_select(clientes_array)) %>
</div>
<div class="span12 field-box">
<label >Cliente Nuevo?</label>
<%= check_box_tag 'con_cliente',
'ClienteNuevo', false
%>
</div>
<div id="cliente_form">
<%= f.fields_for :cliente do |cliente_builder| %>
<div class="span12 field-box">
<label>Nombre:</label>
<%= cliente_builder.text_field(:nombre, class:
"span9") %><br />
</div>
and here is the controller:
class ChecksController < ApplicationController
def checkin
@reserva = Reserva.new
cliente = @reserva.build_cliente
end
when i try to add a reservation, i complete the client fields_for but when
the reservation is created, the client is equal to nil....
Any ideas ??
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/0c8a7d18-7d96-4b97-821d-c8e25c86cf9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.