ruby - How do I get the root directory of a Rails app in a Gem -


is possible know rails file system root of application in code of gem included in app?

this sample of gem source:

module mygem   def self.included(base)     puts rails.root # return nil   end end  actioncontroller::base.send :include, mygem 

thank's , sorry poor english

the solution found fix similar problem include module using railtie initializers.

so, in /lib/mygem/railtie.rb

module mygem   class railtie < rails::railtie     initializer "include code in controller"       activesupport.on_load(:action_controller)         include mygem       end     end end 

with code, module included after actioncontroller loaded , able use rails.root

let me know if works you.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -