Rails - 给定@Comments - 如何在不重新点击数据库的情况下获得倒数第二条评论 [英] Rails - Given @Comments - how to obtain the 2nd to last comment w/o rehitting the db

查看:32
本文介绍了Rails - 给定@Comments - 如何在不重新点击数据库的情况下获得倒数第二条评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定的@comments 可以包含 1 个或多个记录.如何获得倒数第二条评论?

given @comments which can contain 1 or more records. How do I obtain the 2nd to last comment?

谢谢

推荐答案

我想这也可以称为倒数第二条记录:

I suppose that would also be called the penultimate record:

@comments[-2]

这里是文档1 Ruby 有趣的索引运算符.

Here are the docs1 to Ruby's interesting index operator.

<小时>1.Rubyists,请注意我是如何链接它的.如果您从 ruby​​-doc 链接中删除该版本,则引用将是持久且最新的.

这篇关于Rails - 给定@Comments - 如何在不重新点击数据库的情况下获得倒数第二条评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆