向ActiveAdmin添加数值范围过滤 [英] Adding Numeric Range Filtering to ActiveAdmin
问题描述
2015年问候与节日快乐-
Greetings and Happy Holidays 2015 --
我尝试根据 Boris Stall的出色博客文章添加数值范围过滤.
我正在跑步:
- 导轨4.2.4
- Ruby 2.2.3
- ActiveAdmin 1.0.0pre2
我一直遇到此错误:
找不到输入类NumericRangeInput
Unable to find input class NumericRangeInput
这是我的config/initializers/active_admin/filter_numeric_range_input.rb
Here is my config/initializers/active_admin/filter_numeric_range_input.rb
module ActiveAdmin
module Inputs
class FilterNumericRangeInput < ::Formtastic::Inputs::StringInput # Add filter module wrapper
include ActiveAdmin::Inputs::Filters::Base
def to_html
input_wrapping do
[ label_html,
builder.text_field(gt_input_name, input_html_options(gt_input_name)),
template.content_tag(:span, "-", :class => "seperator"),
builder.text_field(lt_input_name, input_html_options(lt_input_name)),
].join("\n").html_safe
end
end
def gt_input_name
"#{method}_gteq"
end
alias :input_name :gt_input_name
def lt_input_name
"#{method}_lteq"
end
def input_html_options(input_name = gt_input_name)
current_value = @object.send(input_name)
{ :size => 10, :id => "#{input_name}_numeric" , :value => current_value }
end
end
end
end
我只是在尝试:
filter :id, as: :numeric_range
我已经研究了集成AA,Ransack,Formtastic等的潜在问题,但是我还没有足够的能力去知道从这里出发的去向.任何帮助将不胜感激.
I've researched the potential issues integrating AA, Ransack, Formtastic, etc., but I'm not advanced enough to know where to go from here. Any help is greatly appreciated.
推荐答案
看来,较新版本的ActiveAdmin可能有不同的策略来加载或命名输入模块中的其他类.我注意到文件中的类名称称为FilterNumericRangeInput
.因此,AA必须采取一些措施来转换名称,我们只需要弄清楚要正确转换的符号即可.因此,作为实验,我尝试将app/admin/test.rb
中的符号重命名为:
It seems newer versions of ActiveAdmin might have a different strategy for loading or naming other classes in the input module. I noticed that the class name in the file is called FilterNumericRangeInput
. So AA must be doing something to convert the name, we just need to figure out which symbol to give to convert properly. So as an experiment, I tried to rename the symbol in app/admin/test.rb
to:
filter :id, as: :numeric_range_2
我得到了错误:
Unable to find input class NumericRange2Input
因此,根据这个提示,我尝试将符号名称更改为:
So with that hint I tried changing the symbol name to:
filter :id, as: :filter_numeric_range
它奏效了.
这篇关于向ActiveAdmin添加数值范围过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!