# Form\_tag - howto call with self.send?

**URL:** <https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933>\
**Category:** Rails\
**Created:** [December 18, 2008, 10:07am UTC](https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933 "2008-12-18T10:07:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 18, 2008, 10:07am UTC](https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933/1 "2008-12-18T10:07:58Z")

</div>

I have the following code in a form helper Module:

def form\_tag\_helper(options = {})  
url = url\_for(:action =\> “#{@controller.action\_name}”)  
“#{self.send(:form\_tag, url, options)}”  
end

which I call from several views e.g.

```
<%= form_tag_helper %>
  <table>
    <%#= form_input :text_field, "login", :size => 30 %><br/>
    <%#= form_input :password_field, "password", :size => 30 %><br/

```

> 

```
  </table>

  <div class="button-bar">
    <%#= button_helper 'login' %>
    <%#= link_helper 'login_signup', :action => 'signup' %>
    <%#= link_helper 'login_forgot_password', :action =>

```

‘forgot\_password’ %\>

The code – which I have modified from the SaltedHashLoginGenerator  
(replace deprecated start\_form\_tag with form\_tag) – seems to generate  
an html form correctly. I am however conscious that form\_tag (when  
used in the manner above) should have a do…end block surrounding the  
form elements and the above code does not respect this.

I would appreciate any views on this and suggestions on how I might  
add a do…end block.

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 18, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933/2 "2008-12-18T19:19:35Z")

</div>

In Ruby, you can pass a block (a chunk of code) to a method call, and  
then run that code by calling yield in the method. This might be what  
you need… A caveat: I’m pretty much a noob, so anything I say  
might be wrong 🙂

This page looks like it might be helpful:  
[http://tutorial.jcwcn.com/Web-Design/Ruby-on-Rails/Helpers/2007-08-25/3066.html](http://tutorial.jcwcn.com/Web-Design/Ruby-on-Rails/Helpers/2007-08-25/3066.html)

Good luck!

On Dec 18, 1:07 am, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 18, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933/3 "2008-12-18T19:40:05Z")

</div>

On 18 Dec 2008, at 09:07, removed\_email\_address@domain.invalid wrote:

> I have the following code in a form helper Module:
> 
> def form\_tag\_helper(options = {})  
> url = url\_for(:action =\> “#{@controller.action\_name}”)  
> “#{self.send(:form\_tag, url, options)}”  
> end

I’d guess something along the line of  
def form\_tag\_helper(options = {}, &block)  
url = url\_for(:action =\> “#{@controller.action\_name}”)  
form\_tag( url, options, &block)  
end

and then use form\_tag\_helper as you would form\_tag, ie

\<% form\_tag\_helper do %\>  
…  
\<% end \>

should do the trick

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 19, 2008, 11:20am UTC](https://www.ruby-forum.com/t/form-tag-howto-call-with-self-send/155933/4 "2008-12-19T11:20:40Z")

</div>

Thanks! That did do the trick 🙂
