主動聯繫提供了自定義過濾器和範圍時所顯示的索引頁上,像這樣:Activeadmin自定義過濾器和範圍軌道4
我的管理應用程序/管理/ compensatory_off.rb代碼
ActiveAdmin.register CompensatoryOff do
scope :pending, default: true
scope :approved
filter :claim_date, collection: proc { CompensatoryOff.all.map(&:claim_date) }
My Controller for index action :
controller do
def index
@page_title = "Comp-Off"
index! do |format|
if (current_user.has_role? :HRMS_Supervisor)
@compensatory_offs = CompensatoryOff.get_subordinate_employees_comp_offs(current_user).page(params[:page]).per(10)
else
@compensatory_offs = current_user.employee.compensatory_offs.order("compensatory_offs.claim_date DESC").page(params[:page]).per(10) if current_user.employee
end
format.html {
render "active_admin/resource/index"
}
end
end
end
end
我在上面的代碼中同時使用了過濾器和範圍。
在我的模型我所定義的範圍也
class CompensatoryOff < ActiveRecord::Base
scope :pending, ->{where(status: "Pending Approval")}
scope :approved, ->{where(status: "Approved")}
#scope :claim_date_eq, -> (claim_date) {where(claim_date: claim_date)}
end
,但在上面的代碼既範圍和過濾器不工作。索引頁面不會導致顯示所有記錄。
注意:當我從控制器刪除我的自定義索引動作範圍和過濾器工作正常。
我的管理應用程序/管理/ compensatory_off.rb代碼
ActiveAdmin.register CompensatoryOff do
scope :pending, default: true
scope :approved
filter :claim_date, collection: proc { CompensatoryOff.all.map(&:claim_date) }
My Controller for index action :
controller do
end
end
如何索引行動資源越來越默認牽強,我想超越我自己的條件指數資源。
任何事情需要與索引操作添加,
請任何幫助我實現這一點,我在努力了很多,找到的結果。
謝謝。
這個代碼給出下面的錯誤, 未定義局部變量或方法'collection_before_scope」爲# –
2014-10-20 10:44:06
沒錯,''scoped_collection是解決方案。 – nistvan 2014-10-20 11:35:01
但分頁不起作用。如何實現這個 – 2014-10-20 11:36:23