Forum: Ruby on Rails Automatic numbering of form components

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7cd9ea64fa126c4e38573828d43df911?d=identicon&s=25 Glenn (Guest)
on 2007-05-10 11:14
(Received via mailing list)

Does anyone how to automatically put sequence number in view?

I have an inquiry form like below.  However, the number of questions
is more than 70, and they are deleted and/reordered in the future.
So, I do not want to hard code the number.  I was trying to create
variable and increment on each question, but everything are displayed
as 1.

I would appreciate if you could tell me any good way to manage this.


<%= start_form_tag :action => 'update' %>
<% Integer @number = 0%>
<div class="row">
<strong><%=h>.</strong> ID Number:
<%=text_field 'person', 'id_number' %>

<div class="row">
<strong><%=h>.</strong> Name:
<%=text_field 'person', 'name' %>

<div class="row">
<strong><%=h>.</strong> Email:
<%=text_field 'person', 'email' %>

...lots of fields...
8d1e089fd6a6703f5f13dbee271aa77c?d=identicon&s=25 Yuri Leikind (Guest)
on 2007-05-10 11:43
(Received via mailing list)

Change .next  to

@number += 1

and it will work


On 5/10/07, Glenn <> wrote:
> <%=text_field 'person', 'id_number' %>
> </div>
> ...lots of fields...
> >

Best regards,
Yuri Leikind
Ba3a00606eb530dcab2c4a6a59bf366d?d=identicon&s=25 Alain Ravet (Guest)
on 2007-05-10 12:53
(Received via mailing list)
> Change .next  to
  > @number += 1

As a side note, if you use the
   fixture_references plugin

, you can even use that trick in fixtures :

file: people.yml
  <% @id=0 %>
    name: John
    id: <%= @id+=1 %>
    name: Bill
    id: <%= @id+=1 %>

7cd9ea64fa126c4e38573828d43df911?d=identicon&s=25 Glenn (Guest)
on 2007-05-11 02:59
(Received via mailing list)
Thank you so much Yuri and Alain!  It worked fine, and it's good to
know I can use this for fixtures.

This topic is locked and can not be replied to.