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
Post a Comment