I am trying to pre-process the params
with to_ar2en_i
function in ApplicationController
before any action processes the params
, I have the following in my application_controller.rb
:
# translates every params' entity from arabic to english
before_action :param_convert_ar2en_i
private
def param_convert_ar2en_i h = nil, path = []
h ||= params
h.each_pair do |k, v|
if v.respond_to?(:key?)
param_convert_ar2en_i v, [path, k].flatten
else
# something like:
params[[path, k].flatten].to_ar2en_i
end
end
end
The problem is I don't know how to apply to_ar2en_i
to a nested params
with the path of [[path, k].flatten]
.
Can anybody kindly help me on this?