def create
@customer=Customer.find(params[:customer_id])
@delivery = @customer.deliveries.build(params[:delivery])
@document = @customer.build_document(params[:document])
if @delivery.valid? and @document.valid?
Delivery.transaction do
@delivery.save!
@document.save!
end
flash[:success] = 'Ok'
respond_with(@customer)
else
@products = Product.all
render 'customers/show', :layout => 'delivery'
end
end
l'action show of customers controller is:
.............
<% content_for :delivery_form do %>
<%= render 'deliveries/form' %>
<% end %>
<% content_for :delivered do %>
<%= render 'delivered/form' %>
<% end %>
I want to see only one of the two content_for depending on @delivery
and @document are saved or not.
I have a form, on submit @delivery and @document are created, if they
are not valid I have to see the show view and in the layout I should
see <%= yield :delivery_form %> while if the objects are valid eand
then saved in the database in the layout I should see <%= yield
:delivered %>.
Based on what I can make the selection?
It' s not the solution.
After I've saved @document and @delivery I go to show action where I
have @delivery=Delivery.new and @document=Document.new, so new_record
is always true.
<p>
<b><%= Customer.human_attribute_name("birth_date") %>:</b>
<% if @customer.birth_date %>
<%= l @customer.birth_date %>
<% else %>
<%= @customer.birth_date %>
<% end %>
</p>
<% content_for :delivery_form do %>
<%= render 'deliveries/form' %>
<% end %>
<% content_for :delivered do %>
<p>
<% if @delivery.valid? and @document.valid? %>
<% for product in @customer.deliveries.last.products %>
<%= product.description %><br />
<% end %>
<% end %>
</p>
<p class="rightText">
<button id="print_button">stampa</button>
</p>
<% end %>