我有这个数组,我的数组中还有很多数据,这个数组只是帮助解决我的问题的一个示例
"[#<PrecintEvent id: 1, name: \"Expo Forum\", address: \"Agustín de Vildósola 251, Villa del Seri, 83280 He...\", phone_number: \"01 652 254 6300\", web_site: \"http://expusforum.com.mx/\", latitude: 29.0468, longitude: -110.961, created_at: \"2019-06-05 19:47:24\", updated_at: \"2019-06-05 19:47:24\">, #<LocationEvent id: 11, name: \"efwfwf\", latitude: nil, longitude: nil, created_at: \"2019-06-06 01:14:44\", updated_at: \"2019-06-06 01:14:44\", address: nil, phone_number: nil, web_site: nil>, #<LocationEvent id: 13, name: \"ewfwf\", latitude: nil, longitude: nil, created_at: \"2019-06-06 01:15:23\", updated_at: \"2019-06-06 01:15:23\", address: nil, phone_number: nil, web_site: nil>]"
我需要能够为我的jquery数据表分页 但是我的代码不起作用
我以这种方式获取数据:
place_events = PlaceEvent.where(event_id: @event.id)
place_events.each do |place_event|
if place_event['event_place_type'] == PrecintEvent.name
data << PrecintEvent.find(place_event['event_place_id'])
else
data << LocationEvent.find(place_event['event_place_id'])
end
end
我对数据进行排序
data = data.sort_by(&:"#{sort_column}")
data = data.reverse if sort_direction == 'desc'
我尝试以这种方式分页数组:
require 'will_paginate/array'
data = data.paginate(:page => page, :per_page => per_page)
def page
params[:start].to_i/per_page + 1
end
def per_page
params[:length].to_i > 0 ? params[:length].to_i : 10
end
def sort_column
columns = %w[name]
columns[params[:order]["0"]["column"].to_i]
end
def sort_direction
params[:order]["0"]["dir"] == "desc" ? "desc" : "asc"
end