0
爲什麼Ransack在我想按日期屬性進行排序時未能對結果進行排序,但是當我嘗試按任何其他類型的屬性排序時,卻無法排序結果?Rails:Ransack無法對Date數據類型進行排序?
無法排序依據「date_received「:
@search = Student.search(params[:q])
@search.sorts = 'date_received' if @search.sorts.empty?
@students = @search.result.includes(:tests).to_a.uniq.
paginate(page: params[:page], per_page: ENTRIES_PER_PAGE)
的成功之處在於排序 '姓氏':
@search = Student.search(params[:q])
@search.sorts = 'last_name' if @search.sorts.empty?
@students = @search.result.includes(:tests).to_a.uniq.
paginate(page: params[:page], per_page: ENTRIES_PER_PAGE)
順便說一句,這是我的學生模型是什麼樣子:
Student(id: integer, first_name: string, last_name: string,
major: string, date_received: date)
給出了什麼?
運行'@ search.result.to_sql'時會得到什麼結果?還要確保條件'if @ search.sorts.empty?'是真的。 – dnsh
當我運行它時,我收到一條錯誤消息:ActionView :: Template :: Error(每個'undefined方法''SELECT'students'。FROM'students'「:String): – ineedahero
另外,我刪除了條件if @ search.sorts.empty?它仍然沒有排序... – ineedahero