问题
Greetings and Happy Holidays 2015 --
I tried to add numeric range filtering per the excellent blog post by Boris Stall.
I'm running:
- Rails 4.2.4
- Ruby 2.2.3
- ActiveAdmin 1.0.0pre2
I keep running into this error:
Unable to find input class NumericRangeInput
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
I'm simply trying:
filter :id, as: :numeric_range
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.
回答1:
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
And I got the error:
Unable to find input class NumericRange2Input
So with that hint I tried changing the symbol name to:
filter :id, as: :filter_numeric_range
And it worked.
回答2:
At this point you just need filter :id, as: :numeric
来源:https://stackoverflow.com/questions/34455537/adding-numeric-range-filtering-to-activeadmin