How can I reload files in / lib for every request?

Rails loads controllers, helpers, and models for every request.

My controllers have tons of modules that include methods for common actions.

Every time I change modules, I have to restart Rails for changes in the actions that will take effect

Any idea how I can say that rails also reload these modules?


Update:

My directory structure looks like this:

  app /
    controllers /
      app1 /
        users_controller.rb
      app2 /
        users_controller.rb

  lib /
    templates /
      controllers /
        users_controller_template.rb

Both App1 :: UsersController and App2 :: UsersController load UsersControllerTeplate as follows:

# app/controllers/app1/users_controller.rb
class App1::UsersController < App1::ApplicationController
  require "templates/controllers/users_controller_template"
  include Templates::Controllers::UsersControllerTemplate
end

# templates/controllers/users_controller_template.rb
module Templates::Controllers::UsersControllerTemplate

  def self.included(base)
    base.class_eval do
      # some class macros called here
    end
  end

  # actions defined here
  def index
  end

end

In application.rb, I added:

config.autoload_paths += %W{ #{config.root}/lib/templates/ }

, , users_controller_template.rb

?

+3
2

autoload_paths application.rb, .

config.autoload_paths << "#{config.root}/lib"
+3

config/application.rb:

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]

Ruby lib, Ruby lib.

+2

All Articles