我使用rails的Datatables服务器端处理。在开发中一切正常。但在生产中没有显示表中的记录。我看到桌子但没有任何记录。 我用railscasts datatables
编写了应用程序我在制作中看到的错误是
Completed 500 Internal Server Error in 9ms
NoMethodError (undefined method `page' for #<ActiveRecord::Relation:0xaafff00>):
我的domains_datatable.rb是
class DomainsDatatable
delegate :params, :h, :link_to, :edit_domain_path, :number_to_currency, to: :@view
def initialize(view)
@view = view
end
def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: Domain.count,
iTotalDisplayRecords: domains.total_count,
aaData: data
}
end
private
def data
domains.each_with_index.map do |domain, key|
[
key+1,
link_to(domain.name, domain),
domain.tic,
domain.indexed,
domain.pr,
domain.notes,
link_to("Edit", edit_domain_path(domain))
]
end
end
def domains
@domains ||= fetch_domains
end
def fetch_domains
domains = Domain.order("#{sort_column} #{sort_direction}")
domains = domains.page(page).per(per_page)
if params[:sSearch].present?
domains = domains.where("name like :search", search: "%#{params[:sSearch]}%")
end
domains
end
def page
params[:iDisplayStart].to_i/per_page + 1
end
def per_page
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
end
def sort_column
columns = %w[name tic indexed pr filter registrator created expires hosting]
columns[params[:iSortCol_0].to_i]
end
def sort_direction
params[:sSortDir_0] == "desc" ? "desc" : "asc"
end
end