user4584963 user4584963 - 2 months ago 6
CSS Question

Unable to wrap div with anchor tags in rails

In my rails app I have a view with a div. The div has a bunch of content including links. I want to make the entire div clickable.

In my view.html.erb file it looks something like this:

<a href="/google">
<div class="container">
content with other anchor tags
</div>
</a>


But it renders like this:

<a href="/google">
</a>
<div class="container">
<a href="/google">
</a>
content with other anchor tags
</div>


Any ideas?

Answer

You need to use a block for your code:

<%= link_to "/google" do %>
  <div class="container">
    content
  </div>
<% end %>

That code will render the following html

<a href="/google">
  <div class="container">
    Content
  </div>
</a>
Comments