Can Rails console reload modules under lib?

后端 未结 4 566
醉话见心
醉话见心 2021-01-30 12:39

I have a module in my Rails project under lib. I run \'rails c\' and do some experimenting in the console. I make a change to the module under lib, type \'reload!\' from the c

4条回答
  •  抹茶落季
    2021-01-30 12:56

    Add the following to config/initializers/reload.rb

    class Object
      def reload_lib!
        Dir["#{Rails.root}/lib/**/*.rb"].map { |f| [f, load(f) ] } #.all? { |a| a[1] } 
        # uncomment above if you don't want to see all the reloaded files
      end
    end
    

    You can now reload all the files in lib by typing reload_lib! in the console

提交回复
热议问题