Nikolay's Blog

Rails Adding <div> Tag

Cover Image for Rails Adding <div> Tag
  • Created at:

As we used to have input_tag, for_tag and other *_tags. There could be a confusing thing when you start looking for div_tag. You quickly realize there's no such

The problem is there can be too many tags in html that rails team aren't able to add them all

Instead of div_tag there's universal tag.div Simply to remember and use:

<%= tag.div tag.p('Hello world!'), class: 'col-md-3' %>

# result:
<div class="col-md-3">
  Hello world
</div>

tag with block

tag accepts block as well:

<%= tag.p do %>
  Hello world
<% end %>

# result:
<div>
  Hello world
</div>

<i> tag for icons

Exactly the same way:

<%= tag.i class: 'icon-cat' %>

# result:
<i class="icon-cat"></i>