Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaorukobo/9245249 to your computer and use it in GitHub Desktop.
Save kaorukobo/9245249 to your computer and use it in GitHub Desktop.
If you make the Rails application as a proxy to other web application, you often meet problems with parameters: "TypeError: expected Hash (got String) for param ". If you want to make Rails(Rack) to ignore these errors, this code helps. Put this in RAILS_ROOT/initializers folder. My environemnt is Ruby 2.0.0p247 + Rails 3.2.12 + Rack 1.4.5.
module Rack::Utils
# to avoid this error:
# home/rack-1.4.5/lib/rack/utils.rb line 127
# raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
unless defined? normalize_params_without_error_passthru
alias normalize_params_without_error_passthru normalize_params
module_function :normalize_params_without_error_passthru
end
def normalize_params(params, *args)
begin
normalize_params_without_error_passthru(params, *args)
rescue
STDERR.puts "[warn] Rack::Utils::normalize_params failed: #{$!}"
return params
end
end
module_function :normalize_params
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment