Reedition of the question (after and thanks to Gavin Miller)
If a have three kind of core extensions (or monkey patches), like these examples:
1- a Form builer
class FormWithBuilder < ActionView::Helpers::FormBuilder
def object
# ... my code
end
end
2- class core extension
class Hash
def translate_values
th=Hash.new
self.each{|k,v| th[k]=I18n.translate(v)}
th
end
end
3- A Form helper
module ActionView
module Helpers
module TranslationHelper
alias_method :original_localize, :localize
def localize(*args)
....
end
end
end
end
where do I have to put these files?
After Gavin Miller response, I understand I have to use the correct folder structure , as Rails core extension and so that. And not havig them under config/initializers
that was where I had before (and working). OK, lets create folders and put them under lib/...
and looking forward deeply I've realized that using config.eager_load_paths and config.autoload_paths is a bad practice:
https://github.com/rails/rails/issues/13142
and recomends to put all this lib/core_extensions
folder that Gavin Miller said to me, under app/lib/
folder and nothing else, but this solution does not work for me, unless I require
all files, but this is what, as I understand, is not necessary because everything inside app
is autoloaded.
I think I'm missing some configuration
This is in images, easier to explain
rails c
Running via Spring preloader in process 9724
Loading development environment (Rails 5.1.5)
2.4.0 :001 > Hash.new.translate_values
NoMethodError: undefined method `translate_values' for {}:Hash
after require it:
2.4.0 :015 > require Rails.root.join('app','lib','core_extensions','hash','localization.rb')
=> true
2.4.0 :016 > Hash.new.translate_values
=> {}
Thanks
---- Edited on 27/10
IS this a bad solution? Just create a file under config/initilizers/core_extensions.rb
and
Dir.glob(Rails.root.join('lib/core_extensions/**/*.rb')).sort.each do |filename|
require filename
end
this way I don't need to modify config.autoload_paths neither eager_load_paths