Why I have one more line?

<% @customer.deliveries.each do |delivery| %> <% end %>
date bag operator district
<%= delivery.delivered_at %> <% delivery.products.each do |product| %> <%= product.description %>,  <% end %> don't know don't know

@customer.deliveries.count give 5 while the table has 6 lines.
Why?
I think it’s all ok but I cannot undestand why the each cycle give me
one more line in the table.

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

<% @customer.deliveries.each do |delivery| %>
don’t know
Why?
Do you mean the table has a total of six rows? If yes then there is
the header row before the 5 data rows.

Colin

On 15 February 2011 10:29, Colin L. [email protected] wrote:

@customer.deliveries.count give 5 while the table has 6 lines. Why?

Do you mean the table has a total of six rows? If yes then there is
the header row before the 5 data rows.

No no, including the header I have a total of 7 rows.
If @customer.deliveries.count is 5 then I expect 6 rows including the
header, instead I have 7 rows including the header.

On 15 February 2011 10:44, Colin L. [email protected] wrote:

<% end %>

What is in the extra row?

here is: <%= @customer.deliveries.count %> this command gives 6

date bag operator
district
2011-02-15 secco, umido, plastica, don’t know don’t know
2011-02-15 secco, umido, plastica, don’t know don’t know
2011-02-15 plastica, don’t know don’t
know
2011-02-15 secco, don’t know don’t know
2011-02-15 secco, umido, plastica, don’t know don’t know
2011-02-15 secco, umido, plastica, don’t know don’t know
don’t
know don’t know

The rows are 8 including the header.

Finally, unless this is rails 3, you should be using
h(product.description) for example, in case there is some html in the
description.

I’m using rails 3.

Consider what would happen if the description included

for example.

I always have one more row.

well the header does not count, just the row of the database, maybe
the last dont its not a row, maybe is the append contentd of the last
row,
check out well your html format

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

@customer.deliveries.count give 5 while the table has 6 lines.
Why?

Do you mean the table has a total of six rows? If yes then there is
the header row before the 5 data rows.

No no, including the header I have a total of 7 rows.
If @customer.deliveries.count is 5 then I expect 6 rows including the
header, instead I have 7 rows including the header.

What is in the extra row?
Also I suggest displaying @customer.deliveries.count in the page to
check it really is what you think.
Finally, unless this is rails 3, you should be using
h(product.description) for example, in case there is some html in the
description. Consider what would happen if the description included

for example.

Colin

maybe is the way you show the data why not prove like these
<% delivery.products.each do |product| %>
<%=“Nothing, just to see if 5 row is display it” %>, 
<% end %>

On 15 February 2011 11:05, Lorenzo Brito M.
[email protected] wrote:

well the header does not count, just the row of the database, maybe
the last dont its not a row, maybe is the append contentd of the last
row,
check out well your html format

I think it’ s ok.
It’ all under <% @customer.deliveries.each do |delivery| %> so if
@customer.deliveries.count gives 5 I’d expect 5 rows.

clear the console where you are running rails server, then start over
and enter to the view and paste the
result of the consol in pastie.org

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

On 15 February 2011 11:13, Lorenzo Brito M.
[email protected] wrote:

maybe is the way you show the data why not prove like these
<% delivery.products.each do |product| %>
<%=“Nothing, just to see if 5 row is display it” %>, 
<% end %>

If you do not already know how to use ruby-debug to break into your
code then have a look at the Rails Guide on debugging, then at this
point insert
<% debugger %>
and when you run it will break here and you can inspect the variables
and see what is going on.

One possiblity, have you changed @customer or its deliveries since it
was read from the database in such a way that the number of records in
the database (deliveries.count) does not match the current number of
deliveries in the object in memory?

Colin

On 15 February 2011 11:13, Lorenzo Brito M.
[email protected] wrote:

maybe is the way you show the data why not prove like these
<% delivery.products.each do |product| %>
<%=“Nothing, just to see if 5 row is display it” %>, 
<% end %>

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


<%= a+=1 %>


<% end %>

@customer.deliveries.count = 5

rows:
1
2
3
4
5
6

On 15 February 2011 11:33, Lorenzo Brito M.
[email protected] wrote:

clear the console where you are running rails server, then start over
and enter to the view and paste the
result of the consol in pastie.org

http://pastie.org/1566058

On 15 February 2011 12:04, Lorenzo Brito M.
[email protected] wrote:

<% end %>

@customer.deliveries.count = 4

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


<%= a+=1 %>
<%= delivery.id %>

1 3
2 4
3 5
4 6
5

there is always one more row :frowning:

the result of
SELECT “deliveries”.* FROM “deliveries” WHERE (“deliveries”.customer_id
= 65145
and check out these
<%= @customer.deliveries.count %>
<% @customer.deliveries.each do |delivery| %>



#just to compare what is in the database and what id is bringing to
you
<%= delivery.id %>


<% end %>

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

 <%= delivery.id %>
<%= a+=1 %> <%= delivery.id %>

1 3
2 4
3 5
4 6
5

there is always one more row :frowning:

What does deliveries.size give?

What are the results of breaking in with the debugger and inspecting the
data

You have not answered whether you have done something in memory to
deliveries since @customer was picked up from the database (presumably
in the controller). Have you added another delivery in the controller
or view?

Colin

give us the controller and the view

but i think what Colin want to see, is the index page , where you are
printing the collection

On 15 February 2011 12:29, Lorenzo Brito M.
[email protected] wrote:

give us the controller and the view

class DeliveriesController < ApplicationController

respond_to :html
debugger
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

end

<%= simple_form_for([@customer, @customer.deliveries.build]) do |f| %>
<%= render ‘shared/error_messages’, :object => @delivery %>

<%= f.input :delivered_at, :as => :hidden, :input_html => { :value => Date.today } %>

Seleziona tutti | Annulla

<% for product in @products %> <%= check_box_tag 'delivery[product_ids][]', product.id, (@delivery.products.include?(product) if @delivery) %> <%= product.description %>
<% end %> <%= f.error :delivery_products %>


<%= simple_fields_for @customer.build_document do |doc| %> <%= render 'shared/error_messages', :object => @document %>

<%= doc.label :doc_type %>:
<%= doc.text_field :doc_type, :value => (params[:document][:doc_type] if @document) %>

<%= doc.label :doc_number %>:
<%= doc.text_field :doc_number, :value => (params[:document][:doc_number] if @document) %>

<%= doc.label :issued_by %>:
<%= doc.text_field :issued_by, :value => (params[:document][:issued_by] if @document) %>

<% end %>

<%= f.submit 'consegna' %>

<% end %>

On 15 February 2011 12:39, Lorenzo Brito M.
[email protected] wrote:

but i think what Colin want to see, is the index page , where you are
printing the collection

here it is:

Consegne:

<% @customer.deliveries.each do |delivery| %> <% end %>
data ora tipo sacchetto operatore circoscrizione
<%= delivery.updated_at.strftime("%d-%m-%Y %T") if delivery.updated_at %> <% delivery.products.each do |product| %> <%= product.description %>,  <% end %> Non si sa ancora Non si sa ancora

stampa

On 15 February 2011 12:23, Colin L. [email protected] wrote:

#just to compare what is in the database and what id is bringing to you

there is always one more row :-(

What does deliveries.size give?

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