Custom Modules

Dan Tappin
I am trying to customize the template and looking to segment my changes into external files as much as possible.  I learned the hard way on my last app when I just started customizing and then lost track of the original code.

For example in the application controller there is this:

include Jumpstart::Controller

which if I read this right is the file located in:

/lib/jumpstart/lib/jumpstart

module Jumpstart
  module Controller
    extend ActiveSupport::Concern

    included do
      prepend_before_action :jumpstart_welcome, if: -> { Rails.env.development? }
    end

    def jumpstart_welcome
      redirect_to jumpstart.root_path(welcome: true) unless File.exist?(Rails.root.join("config", "jumpstart.yml"))
    end
  end
end

I know I can add this to my config:

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

and drop files in the /lib folder etc.  Just trying to understand if there is a standard way to do this before I get too far ahead of myself.  Any pointers or links would be appreciated.
Chris Oliver
All of app/ is autoloaded so I would put your code in there. You can create app/lib or other folders to house your extensions and things as needed.

For example, in Hatchbox I have app/scripts and several other folders that house the logic for deployments, configuring servers, etc.
Dan Tappin
I ended up just just making a single file in /lib.  When I tried making separate files in a nested folder Rails fails to find the modules in the nested folder.
Notifications
You’re not receiving notifications from this thread.
© 2022 GoRails, LLC