Module: ActionView::Helpers::FormTagHelper
- Defined in:
- lib/action_view/helpers/form_tag_helper.rb
Overview
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.
Instance Method Summary collapse
- #check_box_tag(name, value = "1", checked = false, options = {}) ⇒ Object
-
#end_form_tag ⇒ Object
Outputs "".
- #file_field_tag(name, options = {}) ⇒ Object
-
#form_tag(url_for_options = {}, options = {}, *parameters_for_url) ⇒ Object
(also: #start_form_tag)
Starts a form tag that points the action to an url configured with url_for_options just like ActionController::Base#url_for.
- #hidden_field_tag(name, value = nil, options = {}) ⇒ Object
- #password_field_tag(name = "password", value = nil, options = {}) ⇒ Object
- #radio_button_tag(name, value, checked = false, options = {}) ⇒ Object
- #select_tag(name, option_tags = nil, options = {}) ⇒ Object
- #submit_tag(value = "Save changes", options = {}) ⇒ Object
- #text_area_tag(name, content = nil, options = {}) ⇒ Object
- #text_field_tag(name, value = nil, options = {}) ⇒ Object
Instance Method Details
#check_box_tag(name, value = "1", checked = false, options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 63 def check_box_tag(name, value = "1", checked = false, = {}) = {"type" => "checkbox", "name" => name, "id" => name, "value" => value}.update() ["checked"] = "checked" if checked tag("input", ) end |
#end_form_tag ⇒ Object
Outputs ""
30 31 32 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 30 def end_form_tag "</form>" end |
#file_field_tag(name, options = {}) ⇒ Object
46 47 48 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 46 def file_field_tag(name, = {}) text_field_tag(name, nil, .update("type" => "file")) end |
#form_tag(url_for_options = {}, options = {}, *parameters_for_url) ⇒ Object Also known as: start_form_tag
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".
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 14 def form_tag( = {}, = {}, *parameters_for_url) = { "method" => "post" }.merge() if [:multipart] ["enctype"] = "multipart/form-data" .delete(:multipart) end ["action"] = url_for(, *parameters_for_url) tag("form", , true) end |
#hidden_field_tag(name, value = nil, options = {}) ⇒ Object
42 43 44 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 42 def hidden_field_tag(name, value = nil, = {}) text_field_tag(name, value, .update("type" => "hidden")) end |
#password_field_tag(name = "password", value = nil, options = {}) ⇒ Object
50 51 52 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 50 def password_field_tag(name = "password", value = nil, = {}) text_field_tag(name, value, .update("type" => "password")) end |
#radio_button_tag(name, value, checked = false, options = {}) ⇒ Object
69 70 71 72 73 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 69 def (name, value, checked = false, = {}) = {"type" => "radio", "name" => name, "id" => name, "value" => value}.update() ["checked"] = "checked" if checked tag("input", ) end |
#select_tag(name, option_tags = nil, options = {}) ⇒ Object
34 35 36 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 34 def select_tag(name, = nil, = {}) content_tag("select", , { "name" => name, "id" => name }.update()) end |
#submit_tag(value = "Save changes", options = {}) ⇒ Object
75 76 77 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 75 def submit_tag(value = "Save changes", = {}) tag("input", {"type" => "submit", "name" => "submit", "value" => value}.update()) end |
#text_area_tag(name, content = nil, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 54 def text_area_tag(name, content = nil, = {}) if [:size] ["cols"], ["rows"] = [:size].split("x") .delete(:size) end content_tag("textarea", content, { "name" => name, "id" => name }.update()) end |
#text_field_tag(name, value = nil, options = {}) ⇒ Object
38 39 40 |
# File 'lib/action_view/helpers/form_tag_helper.rb', line 38 def text_field_tag(name, value = nil, = {}) tag("input", {"type" => "text", "name" => name, "id" => name, "value" => value}.update()) end |