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_optionsjust 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>
20 21 22 |
# File 'lib/action_view/helpers/tag_helper.rb', line 20 def content_tag(name, content, = {}) "<#{name}#{tag_options(options)}>#{content}</#{name}>" end |
#end_form_tag ⇒ Object
Outputs “</form>”
42 43 44 |
# File 'lib/action_view/helpers/tag_helper.rb', line 42 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.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/action_view/helpers/tag_helper.rb', line 26 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" />
12 13 14 |
# File 'lib/action_view/helpers/tag_helper.rb', line 12 def tag(name, = {}, open = false) "<#{name}#{tag_options(options)}" + (open ? ">" : " />") end |