# Simply helpful form methods?

**URL:** <https://www.ruby-forum.com/t/simply-helpful-form-methods/91202>\
**Category:** Rails\
**Created:** [April 5, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/simply-helpful-form-methods/91202 "2007-04-05T17:05:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [April 5, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/simply-helpful-form-methods/91202/1 "2007-04-05T17:05:35Z")

</div>

Hello everyone,

While working on my little login code, I notice that I write “same” code  
many times like these two lines below.

Email:\<%= text\_field "user", "email", :size =\> 30 %\>

For every input field I gotta write these two lines, imagine I had 10  
input field on every page?

It would make them 20 lines of code, so I thought why not put them in a  
helper method, which will look like this?

def row\_title\_input(title, input, field\_type=“text”)  
“

\<label for=“user\_” + input + “”\>” + title + ":" end

This reduce the lines to 10 🙂 Thats almost fine with me…But again I  
would write this code below 10 times ☹

\<%= row\_title\_input(etc.) %\>

So I thought why not just put the following information in a array?

@input\_form = %w(etc)

and then I can just do this

\<% @input\_form.each do | input | %\>  
\<%= row\_title\_input(etc.) %\>  
\<% end )

Now I’m almost down to 4 lines 🙂

so the question is, does everyone do that? or is it just me who like to  
do things easier or maybe more complicated? are there any easier methods  
to such things?

and thanks for help 🙂

Regards,  
Jamal

DRY = Don’t repeat yourself 🙂

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [April 6, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/simply-helpful-form-methods/91202/2 "2007-04-06T21:02:26Z")

</div>

I just need your opinion 🙂
