Overwrite form helper methods and call old ones in new ones?

Hi all

All my forms should look the same, so I think always putting the right
div etc. tags around them is a violation of the DRY principle.

Until now my forms look like that:

Subject: <%= text_field "news_item", "subject" %>

Now I want the default form helper methods to do that all for me:

<%= text_field “news_item”, “subject”, :label => “Subject” %>

…should produce exactly the same output as the HTML above.

Now I don’t really know how to call the old text_field method to produce
the input tag from within my new method:

application_helper.rb:
def text_field(object_name, method, options = {})
ret_val = “<div class=“text_field”>\n”
ret_val += text_field object_name, method, options # Don’t become
recursive, just call the now overwritten method!
ret_val += “\n”
end

Thanks for help. :slight_smile:
Joshua

If you have the Rails Recipe book, I know there’s a recipe in there
relating
to this…

Kyle S. wrote:

If you have the Rails Recipe book, I know there’s a recipe in there
relating
to this…

Damn, I wanted to order it since quite some weeks, but I don’t have a
Credit Card yet, but I will in some days… Anyone knows further
informations?

you want to investigate the alias method.

Googling for “ruby alias” will turn up enough to get you started.

Max

Max M. wrote:

you want to investigate the alias method.

Googling for “ruby alias” will turn up enough to get you started.

Max

Thank you. I’m gonna try it. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs