ruby - Truncate only older posts in rails -


i have simple block here truncates posts on index.html.erb. want not truncate recent post @ top truncate rest below bulk of page recent post. know easy fix can't seem figure out. appreciated. thanks.

</div>   <% @posts.each |post| %>     <h2 class="title"><%= link_to post.title, post %></h2>       <p><%= truncate(post.body, :length => 300) %></p>       <p class="date"><%= post.created_at.strftime("%b, %d, %y") %></p>     <% end %> </div> 

try this

<div>   <% @posts.each_with_index |post, index| %>     <h2 class="title"><%= link_to post.title, post %></h2>     <p><%= index.zero? ? post.body : truncate(post.body, length: 300) %></p>     <p class="date"><%= post.created_at.strftime("%b, %d, %y") %></p>   <% end %> </div> 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -