# Automatic numbering of form components

**URL:** <https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787>\
**Category:** Rails\
**Created:** [May 10, 2007, 11:14am UTC](https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787 "2007-05-10T11:14:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [May 10, 2007, 11:14am UTC](https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787/1 "2007-05-10T11:14:45Z")

</div>

Hi,

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.

Thanks,  
Glenn

\<%= start\_form\_tag :action =\> ‘update’ %\>  
\<% Integer @number = 0%\>

**\<%=h @number.next%\>.** ID Number: \<%=text\_field 'person', 'id\_number' %\>

**\<%=h @number.next%\>.** Name: \<%=text\_field 'person', 'name' %\>

**\<%=h number.next%\>.** Email: \<%=text\_field 'person', 'email' %\>

…lots of fields…

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [May 10, 2007, 11:43am UTC](https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787/2 "2007-05-10T11:43:47Z")

</div>

Hey

Change .next to

@number += 1

and it will work

Cheers,  
Yuri

On 5/10/07, Glenn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%=text\_field ‘person’, ‘id\_number’ %\>
> 
> …lots of fields…
> 
> >

–  
Best regards,  
Yuri L.

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [May 10, 2007, 12:53pm UTC](https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787/3 "2007-05-10T12:53:55Z")

</div>

> Change .next to  
> @number += 1

As a side note, if you use the  
fixture\_references plugin  
[http://agilewebdevelopment.com/plugins/fixture\_references](http://agilewebdevelopment.com/plugins/fixture_references)

, you can even use that trick in fixtures :

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

## Alain

[blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [May 11, 2007, 2:59am UTC](https://www.ruby-forum.com/t/automatic-numbering-of-form-components/103787/4 "2007-05-11T02:59:54Z")

</div>

Thank you so much Yuri and Alain! It worked fine, and it’s good to  
know I can use this for fixtures.

Glenn
