Creating a Clickable div in Rails Views(erb)

There are many use cases that require an href link to be applied to an entire div. One such situation required an href to be applied to this entire icon in order to make it clickable:

personal-info-clickable-icon.png

The code generated for this is:

personal-info-clickable-icon-code.png

How can this be achieved in Ruby on Rails views(erb)? It’s pretty straightforward and involves creating a simple link_to block:

1
2
3
4
5
6
7
8
9
10
11
<%= link_to subcategory[:path], remote: true do %>
  <div class="col-4 col-xs-4 col-sm-4 col-md-2">
    <div class="tab_image">
      <%= image_tag subcategory[:image] %>
      <span class="small_circle"><%= subcategory[:count] %></span>
    </div>
    <div class='item-title'>
      <%= subcategory[:title] %>
    </div>
  </div>
<% end %>

The subcategory is a hash and it contains a title, items count, image URL, resource path, etc. Happy clicking!