Cycle Background Colors Of Elements In Rails

Posted By Weston Ganger

<p>I was previously having to add extra lines of HTML to achieve this. Stumbled upon this is the rails docs, gonna really come in handy.</p>

<% @posts.each do %>
  <div style="background-color: <%= cycle("red","green","blue", name: "colors");" %>
    <span style="background-color: <%= current_cycle %>">sample text</span>
<% end %>

Article Topic:Software Development - Ruby / Rails

Date:July 04, 2014