using form_tag inside a helper

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

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've been wondering this too! Nothing I've done seems to work.
Only downside I've found to the new way.

- Chris

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.

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

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,