# Using form\_tag inside a helper

**URL:** <https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958>\
**Category:** Rails\
**Created:** [February 8, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958 "2007-02-08T21:20:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [February 8, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958/1 "2007-02-08T21:20:07Z")

</div>

The proper usage of form\_tag nowadays is:

\<% form\_tag do %\>  
blah blah blah  
\<% end %\>

Supposing I want to use form\_tag inside a helper, e.g.

def search\_form  
form\_tag do  
… ??? …  
end  
end

what would I put inside the block? In my other helpers, I build up a  
string and return it.

- donald

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [February 9, 2007, 7:26am UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958/2 "2007-02-09T07:26:59Z")

</div>

Ball, Donald A Jr (Library) wrote:

> ```
> ... ??? ...
> 
> ```
> 
> end  
> end
> 
> what would I put inside the block? In my other helpers, I build up a  
> string and return it.
> 
> - donald

I’ve been wondering this too! Nothing I’ve done seems to work.  
Only downside I’ve found to the new way.

- Chris

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [May 26, 2010, 2:41pm UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958/3 "2010-05-26T14:41:51Z")

</div>

Ball, Donald A Jr (Library) wrote:

> The proper usage of form\_tag nowadays is:
> 
> \<% form\_tag do %\>  
> blah blah blah  
> \<% end %\>
> 
> Supposing I want to use form\_tag inside a helper, e.g.
> 
> def search\_form  
> form\_tag do  
> … ??? …  
> end  
> end
> 
> what would I put inside the block? In my other helpers, I build up a  
> string and return it.
> 
> - donald

I know this post is too old, but I haven’t seen anyone answering this  
question, so here I go.

I found I could use a form\_tag inside a helper method this way:

def search\_form  
form\_tag do  
(  
text\_field\_tag( :name ) +  
text\_field\_tag( :lastname )  
)  
end

I think there should be a cleaner way, but at least this works.

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [July 21, 2010, 11:27am UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958/4 "2010-07-21T11:27:02Z")

</div>

That didn’t quite work for me, but I have made it work using concat:

def search\_form  
form\_tag do  
concat (  
text\_field\_tag( :name ) +  
text\_field\_tag( :lastname )  
)  
end

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [July 21, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/using-form-tag-inside-a-helper/84958/5 "2010-07-21T14:46:49Z")

</div>

Tyler wrote:

> That didn’t quite work for me, but I have made it work using concat:
> 
> def search\_form  
> form\_tag do  
> concat (  
> text\_field\_tag( :name ) +  
> text\_field\_tag( :lastname )  
> )  
> end

You shouldn’t need the concat. It’s not actually doing anything.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

Sent from my iPhone
