Last Updated: May 15, 2019
·
986
· stevo

Avoid problems with constantize returning unexpected results

If in development environment you face problem with constantize returning some unexpected results as mentioned in this issue, there is primitive, yet simple workaround.

Just place following code in any initializer

if Rails.env.development?
  ActiveSupport::Inflector.class_eval do
    def constantize_with_double_call(camel_cased_word)
      constantize_without_double_call(camel_cased_word) && constantize_without_double_call(camel_cased_word)
    end
    alias_method_chain :constantize, :double_call
  end
end