在单双行显示不同的颜色Rails的一些view helper

cycle总是忘了,搬回来标记一下

# 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值