默认的 ActiveAdmin 过滤器不过滤我的索引 table
The default ActiveAdmin filter doesn't filter my index table
我有一个应用程序,您可以在其中填写文档的元数据。我目前的默认过滤有问题,因为它不过滤我的索引 table。过滤器选项显示在右侧,您还可以在选择过滤器并点击按钮后在 url 和参数中看到过滤选项。
utf8=✓&q%5Buser_id_eq%5D=3&commit=Filter&order=id_desc
但是不知何故索引 table 没有刷新。
我唯一的范围是默认范围:
scope :all, default: true
编辑
我认为这与分页有关,因为如果我删除分页,过滤器将再次工作。
这是我 app/admin/DocumentType.rb 文件中当前的索引方法:
def index
index! do |format|
@document_types = DocumentType.where(archived_at: nil).page(params[:page])
file_name = "document_types_#{DateTime.now.strftime('%a_%d_%b_%Y_%H%M%S').downcase}"
format.xls {
spreadsheet = DocumentTypesSpreadsheet.new @document_types
send_data spreadsheet.generate_xls, filename: file_name + ".xls"
}
end
end
索引中只应显示未归档的文档类型,因此我有
@document_types = DocumentType.where(archived_at: nil).page(params[:page])
现在有了这个我的过滤器就不起作用了。但是,如果我完全删除此行,它们将再次工作,除了现在它还显示存档的文档类型。如果我删除 .page(params[:page])
部分,我会收到以下错误消息:
Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.
尝试用这个更新你的控制器
def index
index! do |format|
@document_types = DocumentType.where(archived_at: nil).ransack(params[:q]).result
file_name = "document_types_#{DateTime.now.strftime('%a_%d_%b_%Y_%H%M%S').downcase}"
format.xls {
spreadsheet = DocumentTypesSpreadsheet.new @document_types
send_data spreadsheet.generate_xls, filename: file_name + ".xls"
}
end
end
但您需要确定,您也取消显示了具有这种情况的记录:
.where(archived_at: nil)
因为导出的结果会和显示的不一样
我有一个应用程序,您可以在其中填写文档的元数据。我目前的默认过滤有问题,因为它不过滤我的索引 table。过滤器选项显示在右侧,您还可以在选择过滤器并点击按钮后在 url 和参数中看到过滤选项。
utf8=✓&q%5Buser_id_eq%5D=3&commit=Filter&order=id_desc
但是不知何故索引 table 没有刷新。
我唯一的范围是默认范围:
scope :all, default: true
编辑
我认为这与分页有关,因为如果我删除分页,过滤器将再次工作。
这是我 app/admin/DocumentType.rb 文件中当前的索引方法:
def index
index! do |format|
@document_types = DocumentType.where(archived_at: nil).page(params[:page])
file_name = "document_types_#{DateTime.now.strftime('%a_%d_%b_%Y_%H%M%S').downcase}"
format.xls {
spreadsheet = DocumentTypesSpreadsheet.new @document_types
send_data spreadsheet.generate_xls, filename: file_name + ".xls"
}
end
end
索引中只应显示未归档的文档类型,因此我有
@document_types = DocumentType.where(archived_at: nil).page(params[:page])
现在有了这个我的过滤器就不起作用了。但是,如果我完全删除此行,它们将再次工作,除了现在它还显示存档的文档类型。如果我删除 .page(params[:page])
部分,我会收到以下错误消息:
Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.
尝试用这个更新你的控制器
def index
index! do |format|
@document_types = DocumentType.where(archived_at: nil).ransack(params[:q]).result
file_name = "document_types_#{DateTime.now.strftime('%a_%d_%b_%Y_%H%M%S').downcase}"
format.xls {
spreadsheet = DocumentTypesSpreadsheet.new @document_types
send_data spreadsheet.generate_xls, filename: file_name + ".xls"
}
end
end
但您需要确定,您也取消显示了具有这种情况的记录:
.where(archived_at: nil)
因为导出的结果会和显示的不一样