# Form\_tag code block

**URL:** <https://www.ruby-forum.com/t/form-tag-code-block/85864>\
**Category:** Rails\
**Created:** [February 16, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864 "2007-02-16T22:13:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [February 16, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864/1 "2007-02-16T22:13:13Z")

</div>

I have this in a template-\>

Hello  
\<% form\_tag :action =\> “create” do %\>  
My pretty form!  
\<% end %\>

And all I’m getting at output is -\>

Hello

Actually, any actionview helper that is supposed to take a code block  
is not working for me. What wicked stupid thing am I missing here?

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [February 16, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864/2 "2007-02-16T22:20:26Z")

</div>

> Hello  
> \<% form\_tag :action =\> “create” do %\>  
> My pretty form!  
> \<% end %\>

you need to use \<%= on the form tag even if you use the block method

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [February 16, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864/3 "2007-02-16T22:29:15Z")

</div>

Thanks for the reply!

Sadly, though, I tried that.

Error-\>

compile error  
C:/INSTAN~1/rails\_apps/lumina\_erp/config/…/app/views/bom\_lines/  
edit.rhtml:2: parse error, unexpected ‘)’  
\_erbout.concat(( form\_tag :action =\> “create” do ).to\_s);  
\_erbout.concat “\n”  
^  
C:/INSTAN~1/rails\_apps/lumina\_erp/config/…/app/views/bom\_lines/  
edit.rhtml:5: parse error, unexpected kEND, expecting ‘)’

Obvioulsy from the error message you can see that this is on a M$  
machine (InstantRails 1.4 WinXP).

Anyways, just tried it on Ubuntu server and it works fine. Must be a  
problem with InstantRails.

So to recap… The first way I posted (and that’s all over  
[api.rubyonrails.org](http://api.rubyonrails.org)) is correct. I’m gonna try and update activeview  
through gem now I guess.

Thanks for your help!

On Feb 16, 4:20 pm, Keynan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [February 17, 2007, 3:11am UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864/4 "2007-02-17T03:11:48Z")

</div>

julian wrote:

> I have this in a template-\>
> 
> Hello  
> \<% form\_tag :action =\> “create” do %\>  
> My pretty form!  
> \<% end %\>
> 
> And all I’m getting at output is -\>
> 
> Hello
> 
> Actually, any actionview helper that is supposed to take a code block  
> is not working for me. What wicked stupid thing am I missing here?

This format require rails 1.2. If you are on 1.1.6 you have to use:

\<%= form\_tag :action =\> ‘create’ %\>  
Form!  
\<%= end\_form\_tag %\>

And you can never use blocks with \<%= %\> with ERb because of the way ERb  
is evaluated within the blocks.

This will always yield an error. What does \<%= end %\> output in this  
context?

\<%= foo do %\>  
\<%= ‘foo’ %\>  
\<%= end %\>

Only way to do this is:

\<% foo do %\>  
\<%= ‘foo’ %\>  
\<% end %\>

But if you want to do form tags with blocks you use 1.2.

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [February 17, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/form-tag-code-block/85864/5 "2007-02-17T14:32:28Z")

</div>

Have you tried adding form fields to the form tag? i.e.

Hello  
\<% form\_tag :action =\> “create” do %\>

My pretty form!

\<%= text\_field "foo", "bar" %\>

\<%= submit\_tag "Do it!" %\>

\<% end %\>

Also when you said it only outputted Hello was that what you saw  
rendered in the browser or was that the source of the output?

Niels
