如何在 Rails 中的每个函数中指定条件。
@page = 1
@allRecords = #This result will come from API.. It have 500 records.
resultArray = []
@allRecords.each do |t| #need to specify condition here based on @page value
#processes...
resultArray << t
end
render :json => resultArray
我会将@page number 发送给控制器。然后resultArray将发送最终值
Input : @page = 1
Output : resultArray = Records 1 - 50
Input : @page = 2
Output : resultArray = Records 51 - 100
Input : @page = 3
Output : resultArray = Records 101 - 150
like wise...
我怎样才能做到这一点。
任何帮助,将不胜感激。谢谢。