My problem is I wanted to insert a <span>
tag in form_for label
custom text. In normal html code, it would be like this:
<label>Address<span class="required">*</span></label>
but it Rails, how would I insert it in here:
<%= f.label :address, "Address" %>
It's just an indication for required fields.
As most of the Form helpers, you can pass a do/block instead of the name argument:
<%= f.label :address do %>
Address<span class="required">*</span>
<% end %>
Works with link_to
also:
<%= link_to root_path do %>
<div>Hey!</div>
<% end %>
You can just do like this
<%= f.label :address, "Address<span class='required'>*</span>".html_safe %>
This produces the following HTML
<label for="address">Address<span class="required">*</span></label>
OR
You can do like this too.
<%= f.label :address do %>
Address<span class="required">*</span>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With