Module: Extensions::Core::Hash

Defined in:
lib/rails_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_fields(fields = {}, namespace = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rails_ext.rb', line 43

def to_fields(fields = {}, namespace = nil)
  each do |key, value|
    key = namespace ? "#{namespace}[#{key}]" : key
    case value
    when ::Hash
      value.to_fields(fields, key)
    when ::Array
      fields["#{key}[]"] = value
    else
      fields[key.to_s] = value
    end
  end
  fields
end