The solution I found to fix a similar problem is to enable my module using railtie initializers.
So in your /lib/mygem/railtie.rb
module MyGem
class Railtie < Rails::Railtie
initializer "Include your code in the controller" do
ActiveSupport.on_load(:action_controller) do
include MyGem
end
end
end
With this code, your module will be enabled after loading the ActionController, and you can use Rails.root
Let me know if this works for you.
Gianu source
share