0

如果我有一个循环,我正在尝试获取最新的记录。我收到此语法错误:

<% @user.pictures[0,5].order('created_at DESC').each_with_index do |s, i| %>
  <% link_to ... %>
<% end %>

我的错误来自

undefined method `order'

获取最新记录的正确语法是什么?

谢谢

4

1 回答 1

1

尝试限制:

<% @user.pictures.order('created_at DESC').limit(5).each_with_index do |s, i| %>

@user.pictures[0, 5]返回一个数组,而数组没有order方法,这就是您收到该错误的原因。

于 2013-08-11T03:50:04.800 回答