Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of each row.

I have in my database 3 records and i want that they looks like: if I using for (each)

<% @records.each do |record| %>
  1. record1
  2. record2
  3. record3
like image 599
Vitali Zakharoff Avatar asked Mar 24 '11 15:03

Vitali Zakharoff


People also ask

What is number of row?

A row is several data banks (cells) laid out horizontally in a table or spreadsheet. For example, in the picture below, the row headers (row numbers) are numbered 1, 2, 3, 4, 5, etc. Row 16 is highlighted in red and cell D8 (on row 8) is the selected cell.

How do you calculate the number of rows?

If you need a quick way to count rows that contain data, select all the cells in the first column of that data (it may not be column A). Just click the column header. The status bar, in the lower-right corner of your Excel window, will tell you the row count.

How do I number every row in SQL?

If you'd like to number each row in a result set, SQL provides the ROW_NUMBER() function. This function is used in a SELECT clause with other columns. After the ROW_NUMBER() clause, we call the OVER() function. If you pass in any arguments to OVER , the numbering of rows will not be sorted according to any column.


1 Answers

You probably want each_with_index. something like:

<% @records.each_with_index do |record, i| %>
   <%= (i+1) %>. <%= record.foo %> <br />
<% end %>
like image 94
Matt Greer Avatar answered Oct 20 '22 18:10

Matt Greer