Ruby on rails 如何在数组中指定条件

Ruby on rails 如何在数组中指定条件,ruby-on-rails,arrays,ruby-on-rails-3,each,Ruby On Rails,Arrays,Ruby On Rails 3,Each,如何在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 :

如何在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 = 1
@allRecords = #This result will come from API.. It have 500 records.
per_page = 50
resultArray = @allRecords.slice(@page + (@page - 1) * per_page, per_page)
# if result is not Array (Enumerable)
#resultArray = @allRecords.to_a.slice(@page + (@page - 1) * per_page, per_page) 
@page = 1
@allRecords = #This result will come from API.. It have 500 records.
per_page = 50
resultArray = @allRecords.slice(@page + (@page - 1) * per_page, per_page)
# if result is not Array (Enumerable)
#resultArray = @allRecords.to_a.slice(@page + (@page - 1) * per_page, per_page)