Simply helpful form methods?

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 :slight_smile: Thats almost fine with me…But again I
would write this code below 10 times :frowning:

<%= 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 :slight_smile:

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 :slight_smile:

Regards,
Jamal

DRY = Don’t repeat yourself :slight_smile:

I just need your opinion :slight_smile: