Module: TyphoeusFix

Defined in:
lib/typhoeus_fix/array_decoder.rb

Overview

Typhoeus encodes arrays as hashes {‘0’ => v0, ‘1’ => v1, .., ‘n’ => vN }

To fix this in your rails server your should: in Gemfile:

gem 'logical_model', '~> 0.3.2'

in application_controller.rb:

require 'typhoeus_fix/array_decoder'
class ApplicationController < ActionController::Base
  include TyphoeusFix
  before_filter :decode_typhoeus_arrays
end

Instance Method Summary collapse

Instance Method Details

#decode_typhoeus_arraysObject



18
19
20
# File 'lib/typhoeus_fix/array_decoder.rb', line 18

def decode_typhoeus_arrays
  deep_decode(params)
end

#deep_decode(hash) ⇒ Object

Recursively decode Typhoeus encoded arrays



23
24
25
26
27
28
29
30
31
# File 'lib/typhoeus_fix/array_decoder.rb', line 23

def deep_decode(hash)
  return hash unless hash.is_a?(Hash)
  hash.each_pair do |key,value|
    if value.is_a?(Hash)
      deep_decode(value)
      hash[key] = value.decode_typhoeus_array
    end
  end
end