部分收集来自: https://segmentfault.com/a/1190000000484781
1.表单隐藏元素的使用
<%f.hidden_field :task_id, :value => task.id%>
2.cycle(first_value, *values)
<tr class="<%= cycle('list_line_odd', 'list_line_even') %>"></tr> <!--->cycle设置奇偶数为指定样式<---->
3.image_tag生成image标签
<%= image_tag(product.image_url, class: 'list_image') %>
4.strip_tags(html)清除html标签
strip_tags("Strip <i>these</i> tags!")
# => Strip these tags!
5.truncate截取字符
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)"
6.时间转换方法
product.updated_at.localtime.strftime('%Y/%m/%d %H:%S')
7.一般我们通过多对多关系获取到的数据都是一个集合对象,我们需要通过使用to_a方法将其转换成数组
line_items.to_a.sum {|item| item.total_price}