下一个/上一个按钮来回移动对象

Next / Previous button to go to & fro through objects

我正在尝试通过 Rails 中的对象来回执行操作。

版本:

  1. Rails: 4.2.5
  2. Ruby: 2.3.0

所以要求是:我有一个 id 数组。有向上和向下按钮。如果我点击向下,它会导航到下一个对象,反之亦然。导航应该仅从数组中的特定对象 ID 发生。

有什么建议吗?

所以我已经用 Ajax 解决了这个问题。 我将所有 ID 保留在会话中。 & 我每次都检查索引 & 通过查询我将转到下一个 ID & 只需通过 Ajax 刷新页面。

制作了 2 个方法作为下一个和上一个。

all_next_ids = session[:ids]
index_of_current = all_next_ids.index(current_id) # current id when clicked
next_id = all_nexts[index_of_current + 1]

Then from query find the next id object

对上一个做同样的事情。