Permalink
Browse files

Modified method of transforming 'except' argument into an array in fi…

…elds_for_params, per suggestion from jpmckinney. Also added a spec to test this case.
  • Loading branch information...
1 parent 85bbf46 commit a8252ea4c2ae1c7b47f0961e95376784f3375722 @tinynumbers tinynumbers committed Aug 27, 2012
Showing with 8 additions and 4 deletions.
  1. +1 −2 lib/active_admin/view_helpers/fields_for.rb
  2. +7 −2 spec/unit/view_helpers/fields_for_spec.rb
@@ -15,11 +15,10 @@ module FormHelper
#
def fields_for_params(params, options = {})
namespace = options[:namespace]
- except = options[:except]
+ except = options[:except].is_a?(Array) ? options[:except] : [options[:except]]
params.map do |k, v|
next if namespace.nil? && %w(controller action commit utf8).include?(k.to_s)
- next if except && k.to_s == except.to_s
next if except.is_a?(Enumerable) && except.map(&:to_s).include?(k.to_s)
if namespace
@@ -14,6 +14,11 @@
should == [ { :scope => "All" } ]
end
+ it "should allow an array for the except" do
+ fields_for_params({:scope => "All", :name => "Greg", :age => "12"}, :except => [:name, :age]).
+ should == [ { :scope => "All" } ]
+ end
+
it "should work with hashes" do
params = fields_for_params(:filters => { :name => "John", :age => "12" })
@@ -29,8 +34,8 @@
it "should work with arrays" do
fields_for_params(:people => ["greg", "emily", "philippe"]).
- should == [ { "people[]" => "greg" },
- { "people[]" => "emily" },
+ should == [ { "people[]" => "greg" },
+ { "people[]" => "emily" },
{ "people[]" => "philippe" } ]
end
end

0 comments on commit a8252ea

Please sign in to comment.