Ruby 如何取得查询结果的每条数据行所在索引?

ikebukuro · April 18, 2012 · Last by ikebukuro replied at April 18, 2012 · 2030 hits
@users = User.find_by_sql sql

方式取得的数据,

@users.each do |user|
# ...
end

循环输出时,如何得到每条数据的索引值?

each_with_index

非常干净的回答。 谢谢。

You need to Sign in before reply, if you don't have an account, please Sign up first.