cycle总是忘了,搬回来标记一下
还有两个helper
也可以一起
# Alternate CSS classes for even and odd numbers...
@items = [1,2,3,4]
<table>
<% @items.each do |item| %>
<tr class="<%= cycle("even", "odd") -%>">
<td>item</td>
</tr>
<% end %>
</table>
# Cycle CSS classes for rows, and text colors for values within each row
@items = x = [{:first => 'Robert', :middle => 'Daniel', :last => 'James'},
{:first => 'Emily', :middle => 'Shannon', :maiden => 'Pike', :last => 'Hicks'},
{:first => 'June', :middle => 'Dae', :last => 'Jones'}]
<% @items.each do |item| %>
<tr class="<%= cycle("odd", "even", :name => "row_class") -%>">
<td>
<% item.values.each do |value| %>
<%# Create a named cycle "colors" %>
<span style="color:<%= cycle("red", "green", "blue", :name => "colors") -%>">
<%= value %>
</span>
<% end %>
<% reset_cycle("colors") %>
</td>
</tr>
<% end %>
还有两个helper
也可以一起
truncate("Once upon a time in a world far far away")
# => "Once upon a time in a world..."
truncate("Once upon a time in a world far far away", :length => 17)
# => "Once upon a ti..."
truncate("Once upon a time in a world far far away", :length => 17, :separator => ' ')
# => "Once upon a..."
truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (continued)')
# => "And they f... (continued)"
truncate("<p>Once upon a time in a world far far away</p>")
# => "<p>Once upon a time in a wo..."
pluralize(1, 'person')
# => 1 person
pluralize(2, 'person')
# => 2 people
pluralize(3, 'person', 'users')
# => 3 users
pluralize(0, 'person')
# => 0 people