How to use form_tag from helper?

I have an assistant that I use to create a form. The parameters that are used to create the form fields are passed to the helper. I cannot figure out how to use a block outside the template.

For example:

def generate_form(path, fields) form_tag(path, method: :get) do # what do I do in here? end end 

When I process partial parts inside a block, nothing is displayed on the displayed web page. If I combined a bunch of tags (field_tag, text_field_tag, etc.), then raw html will appear on the page.

I am using Rails 3.1.0

+7
source share
1 answer

Rails element helpers return strings, so you can do:

 def generate_form(path, fields) s = form_tag(path, method: :get) do p = input_tag p << submit_tag #(everything will be wrapped in form tag) p #returns p from block end s.html_safe #returns s and avoids html escaping end 
+11
source

All Articles