Embedding a full form in a helper

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?

form_for does not work in a helper. Use a partial instead.

Aaron

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