Why I have one more line?

On 15 February 2011 15:16, Mauro [email protected] wrote:

<td>

<% @customer.deliveries.each do |delivery| %>

there is always one more row :frowning:

What does deliveries.size give?

mmmm delvieries.count gives 4 while deliveries.size gives 5.

FOUND!!
Thank to Colin and his suggest deliveries.size here is the problem:
In the customer show view I have:

<%= Customer.human_attribute_name("taxable_address") %>: <%= @customer.taxable_address %>

<% debugger %>

<% content_for :delivery_form do %>
<%= render ‘deliveries/form’ %>
<% end %>

<% content_for :delivered do %>
<%= debug params %>
<%= render ‘customers/deliveries’ %>
<% end%>

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.

So, that in your index view also has a form?so the problem was the if

so how you solve the problem?

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:

<%= Customer.human_attribute_name("taxable_address") %>: <%= @customer.taxable_address %>

. . .

<% content_for :delivery_form do %>
<%= render ‘deliveries/form’ %>
<% end %>

<% content_for :delivered do %>
<%= render ‘customers/deliveries’ %>
<% end%>

in the layout I had:

<% 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.

No hay problema, de casualidad no eres de mexico? jaja yo igual soy

On 15 February 2011 23:59, Lorenzo Brito M.
[email protected] wrote:

No hay problema, de casualidad no eres de mexico? jaja yo igual soy

I’m italian, from Sardinia.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs