Rawan _ Rawan _ - 2 months ago 13
Ruby Question

How to use link_to in rails to put multiple things in a single link?

This is my code:

<div class="column">
<div class="post-module">
<a href="https://www.livescience.com/59802-should-we-fear-
intelligent-robots.html" >
<div class="thumbnail">
<div class="date">
<div class="day">14</div>
<div class="month">Jul</div>
</div>
<img src="#"/>
</div>
<div class="post-content">
<div class="category">Robots</div>
<h1 class="title">Should We Fear The Rise of Intelligent
Robots? </h1>
<h2 class="sub_title"> Robots will unite. </h2>
<p class="description"></p>
</div>
</a>
</div>
</div>


I want to make that code in rails but I am just a beginner in rails and I wasn't able to find something that could help me in this. I only know the basic idea of the link_to in rails.

Answer Source

link_to method can take a block and display it's evaluation as a link content:

<%= link_to "https://www.livescience.com/59802-should-we-fear-intelligent-
  robots.html" do %>
   <div class="thumbnail">
     <div class="date">
         <div class="day">14</div>
             <div class="month">Jul</div>
                 </div><img src="#"/>
             </div>
             <div class="post-content">
                 <div class="category">Robots</div>
                 <h1 class="title">Should We Fear The Rise of 
                 Intelligent Robots? </h1>
                 <h2 class="sub_title"> Robots will unite. </h2>
                 <p class="description"></p>
             </div> 
<% end %>