Hello everyone,
While working on my little login code, I notice that I write "same"
code
many times like these two lines below.
<dt><label id="user_email">Email:</label></dt>
<dd><%= text_field "user", "email", :size => 30
%></dd>
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")
"<dt><label for=\"user_" + input +
"\">" + title + ":</label></dt>
<dd><input id=\"user_" + input + "\"
name=\"user[" + input + "]\"
size=\"30\" type=\"" + field_type + "\"
/></dd>"
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 :)
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---