# Embedding a full form in a helper

**URL:** <https://www.ruby-forum.com/t/embedding-a-full-form-in-a-helper/126943>\
**Category:** Rails\
**Created:** [January 23, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/embedding-a-full-form-in-a-helper/126943 "2008-01-23T17:08:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [January 23, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/embedding-a-full-form-in-a-helper/126943/1 "2008-01-23T17:08:07Z")

</div>

I am trying to get this to work:

def do\_button(event\_type)  
varname = event\_type.name.underscore  
humanname = event\_type.new.event\_name\_string  
form\_for (@user, :url =\> “do\_#{varname}\_user\_path(@user)”) do |  
form|  
submit\_tag “I got my #{humanname} today”  
end  
end

My view has this in it:

```
  <li>
    <% do_button(Mammogram) %>
  </li>

```

But I keep getting this error in the log from the form\_for line inside  
the helper:

ActionView::TemplateError (undefined local variable or method  
`\_erbout’ for ActionView::Base:0x357355c) in users/  
\_mammogram.html.erb.

Can’t figure out what to do. Anyone?

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [January 23, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/embedding-a-full-form-in-a-helper/126943/2 "2008-01-23T17:46:24Z")

</div>

form\_for does not work in a helper. Use a partial instead.

Aaron

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [February 18, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/embedding-a-full-form-in-a-helper/126943/3 "2008-02-18T17:53:16Z")

</div>

Hi.

I have the same problem…

As I’m still trying to find whats wrong I can only share some guesses:

1. The error is the same as when you do something like this in the  
view:

\<%= form\_for(@user) do |f| %\>

(note the ‘=’)

So my guess is that what happens is that the block treats all the code  
as it was inside \<%= %\>-tags and therefore breaking the “sub-block”…

Please let me know if you find a solution to the problem…

Thanks,  
Nicklas
