uncamelcase params
[arvados.git] / app / controllers / application_controller.rb
1 class ApplicationController < ActionController::Base
2   protect_from_forgery
3   before_filter :uncamelcase_params_hash_keys
4
5   protected
6
7   def uncamelcase_params_hash_keys
8     uncamelcase_hash_keys(params)
9   end
10
11   def uncamelcase_hash_keys(h)
12     if h.is_a? Hash
13       nh = Hash.new
14       h.each do |k,v|
15         if k.class == String
16           nk = k.underscore
17         elsif k.class == Symbol
18           nk = k.to_s.underscore.to_sym
19         else
20           nk = k
21         end
22         nh[nk] = uncamelcase_hash_keys(v)
23       end
24       h.replace(nh)
25     end
26     h
27   end
28 end