Method: ActionView::Helpers::FormTagHelper#label_tag
- Defined in:
- actionview/lib/action_view/helpers/form_tag_helper.rb
#label_tag(name = nil, content_or_options = nil, options = nil, &block) ⇒ Object
Creates a label element. Accepts a block.
Options
-
Creates standard HTML attributes for the tag.
Examples
label_tag 'name'
# => <label for="name">Name</label>
label_tag 'name', 'Your name'
# => <label for="name">Your name</label>
label_tag 'name', nil, class: 'small_label'
# => <label for="name" class="small_label">Name</label>
281 282 283 284 285 286 287 288 289 290 |
# File 'actionview/lib/action_view/helpers/form_tag_helper.rb', line 281 def label_tag(name = nil, = nil, = nil, &block) if block_given? && .is_a?(Hash) = = .stringify_keys else ||= {} = .stringify_keys end ["for"] = sanitize_to_id(name) unless name.blank? || .has_key?("for") content_tag :label, || name.to_s.humanize, , &block end |