SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Monday, March 9, 2009

Cycle helper for rails

Cycle helper comes under ActionView::Helpers::TextHelper,The TextHelper module provides a set of methods for filtering, formatting and transforming strings, which can reduce the amount of inline Ruby code in your views. These helper methods extend ActionView making them callable within our template files.

Cycle


Creates a Cycle object whose to_s method cycles through elements of an array every time it is called. This can be used for example, to alternate classes for table rows. You can use named cycles to allow nesting in loops. Passing a Hash as the last parameter with a :name key will create a named cycle. The default name for a cycle without a +:name+ key is "default". You can manually reset a cycle by calling reset_cycle and passing the name of the cycle..

For example my requirement to display the content will be like this



So at starting level i went to display the page using some if else condition,then went to use cycle helper
<%@articles.each do |article| %>
<div class="<%= cycle( "results odd","results even") -%>">

<p>
<%=article.description %>
</p>

</div>
<%end%>