ajax-datatables-rails在数据表中搜索时遇到问题

时间:2018-11-02 15:58:52

标签: jquery ruby-on-rails datatable

我有三个模型,SchoolStudentExams。尽管可以相对容易地假定关联,但这是模型结构的样子:

class School < ApplicationRecord
    has_many :students
end

class Student < ApplicationRecord
    belongs_to :school
    has_many :exams
end

class Exam < ApplicationRecord
    belongs_to :student
end

该表实际上显示正确,但是我不能使用搜索功能,因为它给了我常见的错误消息:

  

DataTables警告:表ID = DataTables_Table_0-Ajax错误。欲了解更多   有关此错误的信息,请参见http://datatables.net/tn/7

我无法弄清楚我的join语句出了什么问题。我的意思是,就显示内容而言,它工作正常,但是搜索功能不起作用。我知道ajax-datatable-rails Github页面显示了如何使用嵌套属性,当我只有两个 时,嵌套属性可以正常工作  嵌套的属性。

例如,这有效:

Student.joins(:school).where(schools: {school_name: "Hello World"})

但如果我使用此方法将其嵌套一层以下,则不会:

Exam.joins(student: :school}).where(schools: {school_name: "Hello World"})

实际上,我什至不能简单地使用Exam.joins(student: :school),因为它再次可以正确显示,但无法搜索。

这一定是ajax-datatables-rails所特有的,因为表格可以正确显示但无法搜索。

任何帮助将不胜感激。

0 个答案:

没有答案