Topic: moving form_tag to application helper

View:

<h1>Hello</h1>
<% wrapper %>

Application Helper:

def wrapper; content_tag(:p, content); end
def content; form_tag('/posts'){"blah"}; end

Generated HTML:

<h1>Hello</h1>
<form action="/posts" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="c6ea1982c52214bbf2e8d3317933f6ce81dffc39" /></div>blah</form>

Where are my paragraph tags?  Let's try this:

View (changed <% to <%=):

<h1>Hello</h1>
<%= wrapper %>

Generated HTML:

<h1>Hello</h1>
<form action="/posts" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="c6ea1982c52214bbf2e8d3317933f6ce81dffc39" /></div>blah</form><p><h1>Hello</h1>
<form action="/posts" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="c6ea1982c52214bbf2e8d3317933f6ce81dffc39" /></div>blah</form></p>

OK, now we have paragraph tags, but why is the whole view showing up twice?

Last edited by zephron2000 (2009-08-27 15:41:15)

Re: moving form_tag to application helper

Yeah, I experienced this a while back...  I believe it's a weird bug involving form_tag.  The solution is to have your helper do this:

  def form_from_helper
      content_tag :form, :action => blah_path, :method => :post do
        [(hidden_field_tag :something, some_val),
         (text_field_tag :something_else),
         (submit_tag "Hooray")]
      end
  end

-patrick