Skip to content

Commit a8252ea

Browse files
committed
Modified method of transforming 'except' argument into an array in fields_for_params, per suggestion from jpmckinney. Also added a spec to test this case.
1 parent 85bbf46 commit a8252ea

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/active_admin/view_helpers/fields_for.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ module FormHelper
1515
#
1616
def fields_for_params(params, options = {})
1717
namespace = options[:namespace]
18-
except = options[:except]
18+
except = options[:except].is_a?(Array) ? options[:except] : [options[:except]]
1919

2020
params.map do |k, v|
2121
next if namespace.nil? && %w(controller action commit utf8).include?(k.to_s)
22-
next if except && k.to_s == except.to_s
2322
next if except.is_a?(Enumerable) && except.map(&:to_s).include?(k.to_s)
2423

2524
if namespace

spec/unit/view_helpers/fields_for_spec.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
should == [ { :scope => "All" } ]
1515
end
1616

17+
it "should allow an array for the except" do
18+
fields_for_params({:scope => "All", :name => "Greg", :age => "12"}, :except => [:name, :age]).
19+
should == [ { :scope => "All" } ]
20+
end
21+
1722
it "should work with hashes" do
1823
params = fields_for_params(:filters => { :name => "John", :age => "12" })
1924

@@ -29,8 +34,8 @@
2934

3035
it "should work with arrays" do
3136
fields_for_params(:people => ["greg", "emily", "philippe"]).
32-
should == [ { "people[]" => "greg" },
33-
{ "people[]" => "emily" },
37+
should == [ { "people[]" => "greg" },
38+
{ "people[]" => "emily" },
3439
{ "people[]" => "philippe" } ]
3540
end
3641
end

0 commit comments

Comments
 (0)