Module: ActionView::Helpers::TagHelper
Overview
This is poor man’s Builder for the rare cases where you need to programmatically make tags but can’t use Builder.
Instance Method Summary collapse
-
#content_tag(name, content, options = {}) ⇒ Object
Examples: *
content_tag("p", "Hello world!") => <p>Hello world!</p>
*content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") =>
<div class="strong"><p>Hello world!</p></div>
. -
#end_form_tag ⇒ Object
Outputs “</form>”.
-
#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. -
#tag(name, options = {}, open = false) ⇒ Object
Examples: *
tag("br") => <br />
*tag("input", { "type" => "text"}) => <input type="text" />
.
Instance Method Details
#content_tag(name, content, options = {}) ⇒ Object
Examples:
-
content_tag("p", "Hello world!") => <p>Hello world!</p>
-
content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") =>
<div class="strong"><p>Hello world!</p></div>
21 22 23 |
# File 'lib/action_view/helpers/tag_helper.rb', line 21 def content_tag(name, content, = {}) "<#{name}#{()}>#{content}</#{name}>" end |
#end_form_tag ⇒ Object
Outputs “</form>”
43 44 45 |
# File 'lib/action_view/helpers/tag_helper.rb', line 43 def end_form_tag "</form>" 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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_view/helpers/tag_helper.rb', line 27 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 |
#tag(name, options = {}, open = false) ⇒ Object
Examples:
-
tag("br") => <br />
-
tag("input", { "type" => "text"}) => <input type="text" />
13 14 15 |
# File 'lib/action_view/helpers/tag_helper.rb', line 13 def tag(name, = {}, open = false) "<#{name}#{()}" + (open ? ">" : " />") end |