Search code examples
jqueryruby-on-railslink-to

RoR: link_to tags in a link_to block?


I'm trying to turn a div in to a link but I have link_to tags within my block and this doesn't work. The block stops at the calling of next link_to.

Having looked around for answers I see this is not the right way at all.

<%= link_to tweet_path(tweet.id) do %>
  <div class="tweet-link">
   blah blah
   <% link_to.... %>
   blah blah
   <% link_to.... %>
  </div>
<% end %>

What is the best work around for this problem to get the nested links working as well as my div link? Suggestions? jQuery maybe? ty


Solution

  • It is possible, but not recommmended. Browsers wouldn't know how to read that. It's not a specific rails problem, even if you did it with plain html <a> tags it would lead to unpredictable behaviour.

    See here: https://stackoverflow.com/a/9883044/9595653

    But also here https://css-tricks.com/nested-links/