Provides a number of methods for creating form tags that doesn’t rely on conventions with an object assigned to the template like FormHelper does. With the FormTagHelper, you provide the names and values yourself.
NOTE: The html options disabled, readonly, and multiple can all be treated as booleans. So specifying disabled => :true will give disabled="disabled".
Methods
- check_box_tag
- end_form_tag
- file_field_tag
- form_tag
- hidden_field_tag
- password_field_tag
- radio_button_tag
- select_tag
- start_form_tag
- submit_tag
- text_area_tag
- text_field_tag
Public Instance methods
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 66
66: def check_box_tag(name, value = "1", checked = false, options = {})
67: html_options = { "type" => "checkbox", "name" => name, "id" => name, "value" => value }.update(convert_options(options))
68: html_options["checked"] = "checked" if checked
69: tag("input", html_options)
70: end
Outputs "</form>"
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 32
32: def end_form_tag
33: "</form>"
34: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 48
48: def file_field_tag(name, options = {})
49: text_field_tag(name, nil, convert_options(options).update("type" => "file"))
50: end
Starts a form tag that points the action to an url configured with url_for_options just like ActionController::Base#url_for. The method for the form defaults to POST.
Options:
- :multipart - If set to true, the enctype is set to "multipart/form-data".
This method is also aliased as
start_form_tag
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 17
17: def form_tag(url_for_options = {}, options = {}, *parameters_for_url)
18: html_options = { "method" => "post" }.merge(options.stringify_keys)
19:
20: if html_options["multipart"]
21: html_options["enctype"] = "multipart/form-data"
22: html_options.delete("multipart")
23: end
24:
25: html_options["action"] = url_for(url_for_options, *parameters_for_url)
26: tag("form", html_options, true)
27: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 44
44: def hidden_field_tag(name, value = nil, options = {})
45: text_field_tag(name, value, options.stringify_keys.update("type" => "hidden"))
46: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 52
52: def password_field_tag(name = "password", value = nil, options = {})
53: text_field_tag(name, value, convert_options(options).update("type" => "password"))
54: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 72
72: def radio_button_tag(name, value, checked = false, options = {})
73: html_options = { "type" => "radio", "name" => name, "id" => name, "value" => value }.update(convert_options(options))
74: html_options["checked"] = "checked" if checked
75: tag("input", html_options)
76: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 36
36: def select_tag(name, option_tags = nil, options = {})
37: content_tag("select", option_tags, { "name" => name, "id" => name }.update(convert_options(options)))
38: end
Alias for form_tag
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 78
78: def submit_tag(value = "Save changes", options = {})
79: tag("input", { "type" => "submit", "name" => "submit", "value" => value }.update(convert_options(options)))
80: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 56
56: def text_area_tag(name, content = nil, options = {})
57: options = options.stringify_keys
58: if options["size"]
59: options["cols"], options["rows"] = options["size"].split("x")
60: options.delete("size")
61: end
62:
63: content_tag("textarea", content, { "name" => name, "id" => name }.update(convert_options(options)))
64: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb, line 40
40: def text_field_tag(name, value = nil, options = {})
41: tag("input", { "type" => "text", "name" => name, "id" => name, "value" => value }.update(convert_options(options)))
42: end