My intent was to see content :delivery_form to associate deliveries
and document to customer, while :delivered once Iâve saved delivery
and document in Delivery create action:
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] = âConsegna effettuata.â
respond_with(@customer)
else @products = Product.all
render âcustomers/showâ, :layout => âdeliveryâ
end
end
So in the layout I had:
<% if flash[:success] %>
<%= yield :delivered %>
<% else %>
<%= yield :delivery_form %>
<% end %>
This works, I see content :delivered in the page but content
:delivery_form is always executed.
On 15 February 2011 21:39, Lorenzo Brito M. [email protected] wrote:
So, that in your index view also has a form?so the problem was the if
so how you solve the problem?
I have the form in the show view.
In the index I have a serch form, I search for a customer then show it.
When I have customer details I want also associate a Delivery and a
Document so I put the form under the show view, here it is:
<% if flash[:success] %>
<%= yield :delivered %>
<% else %>
<%= yield :delivery_form %>
<% end %>
the form is in the content :delivery_form, after post, if Delivery and
Document are valid, I redirect to customer show but instead of content
delivery_form I put content delivered.
And this was the error, because content delivery_form is always
executed, and, I donât know why, this increase the
cistomer.deliveries.size.
customer.deliveries.count was, for example 4, but
customer.deliveries.size was 5.
Sorry for my bad english I hope you are understand.