method
label_tag
label_tag(name = nil, content_or_options = nil, options = nil, &block)
public
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>
Register or
log in
to add new notes.
grosser -
September 18, 2008
1 thank
unobstrusive label tag
just use
label_tag('a_a','a_a')
and it works, just not ment for pure decorative labels :)
grosser -
September 17, 2008
0 thanks
removes underscores -> do not use for images etc
example
#does not work label_tag('aa'+image_tag('x_x.gif'))
bansalakhil -
January 9, 2009 - (v2.2.1)
0 thanks
taimoorchangaiz -
June 5, 2013 - (v2.0.3 - v3.2.13)
0 thanks
Html inside Lable tag
I need this
<label> Show <select size="1" name="dyntable_length" aria-controls="dyntable"> <option value="10" selected="selected">10</option> <option value="25">25</option> <option value="50">50</option> <option value="100">100</option> </select> entries </label>
I made a helper method:
def entries_lablel() label_tag '' do concat 'Show ' concat content_tag(:select, options_for_select([10, 25, 50, 100]), {name: 'dyntable_length', size: 1} ) concat ' entries' end end
and In my html.erb file I called it
<%= entries_lablel %>
You can pass paramateres to make it more generic also You can add multiple select elements or any other element using the same