当我使用关联时,我需要使用Ransack sort_link
方法对表中的数据进行排序。
我有:
模型
class Deal < ActiveRecord::Base
has_many :tasks
...
end
class Task < ActiveRecord::Base
belongs_to :deal
...
end
CONTROLLER
...
@search = Deal.where(assigned_to: @user_id).where.not(stage: [6, 7]).search(params[:q])
@deals = @search.result.joins(:tasks).where(assigned_to: @user_id).where.not(stage: [6, 7]).uniq
...
_DEALS.HTML.ERB
...
<th style="width: 15%" class="text-center"><%= sort_link @search, 'tasks.due', "Задача", {}, { :remote => true, :method => :get } %></th>
...
结果是排序不起作用,但是我们从服务器获得了积极的信号:
服务器日志
Processing by DealsController#index as JS
Parameters: {"q"=>{"s"=>"tasks.due desc"}}
Rendered deals/_deals.html.erb (21.0ms)
Rendered deals/index.js.erb (24.8ms)
Completed 200 OK in 39ms (Views: 24.0ms | ActiveRecord: 9.7ms)
已审核了数十个与搜索范围相关的问题,包括Using Ransack to sort attributes for parent of parent和Rails sorting associations with Ransack 但到目前为止他们没有回复。
我怀疑我在https://github.com/activerecord-hackery/ransack中做错了什么。有几个聪明的猜测,但不幸的是他们没有工作。
THX。
答案 0 :(得分:1)