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

**URL:** <https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184>\
**Category:** Rails\
**Created:** [August 16, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184 "2006-08-16T18:32:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 16, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184/1 "2006-08-16T18:32:13Z")

</div>

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. 🙂  
Joshua

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 16, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184/2 "2006-08-16T19:57:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 16, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184/3 "2006-08-16T20:10:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 17, 2006, 12:49am UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184/4 "2006-08-17T00:49:17Z")

</div>

you want to investigate the alias method.

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

Max

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 17, 2006, 8:42am UTC](https://www.ruby-forum.com/t/overwrite-form-helper-methods-and-call-old-ones-in-new-ones/65184/5 "2006-08-17T08:42:16Z")

</div>

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. 🙂
