Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ActionController extension to fix Persian numerals
module ActionControllerParametersExtension
extend ActiveSupport::Concern
# A recursive method to traverse the params hash. It replaces
# persian numerals with their equivalent english numerals.
# It's not the best way to do it, but it works for now.
def fix_numerals(element=self)
case element
when Hash
Hash[{ |k,v| [k, fix_numerals(v)] } ]
when Array{ |v| fix_numerals(v) }
else"۱۲۳۴۵۶۷۸۹۰", "1234567890")
# Includes the extension
ActionController::Parameters.send(:include, ActionControllerParametersExtension)
Copy link

Arvinje commented Dec 12, 2015

This method doesn't return an instance of ActionController::Parameters, so it always has to be called at the end of the chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment