I have a module called user_searches. It performs some searches that aren't core to the user model, thus, why I'm putting the responsibility somewhere else. I want to organize all my models like this that perform non-core user functions in a lib subfolder called user. Right now to include the module's methods in the User model I have to put...
require 'user/user_searches'
class User < ActiveRecord::Base
include UserSearches
end
...I don't need the require if the file is directly in the lib folder, but do if it's in the subfolder. What do I have to do so I don't need the require?
Definition of subfolder : an organizational folder on a computer that is located within another folder …
Directory: A named group of files (a folder); a directory that contains more folders (subdirectories) are called the "parent" and the folder within it is referred to as the "child" of that directory..
A subfolder is housed on the same server and any of its link juice goes back to the domain. An example of a subfolder web address is https://www.impactplus.com/blog. With this structure, all of the pages associated with IMPACT's blog feed the authority of the main domain.
A folder that contains subfolders is referred to as a parent folder. Of the list of top-level folders, only Contracts is a parent folder, as indicated by the little arrow to the left of the folder name.
You could put the necessary require lines into lib/user.rb
that way, all requirements are loaded recursively on application launch.
Alternatively, you could put something like this into an initializer:
# put into config/initializers/load_lib.rb
Dir["#{RAILS_ROOT}/lib/**/*.rb"].each { |f| require(f) }
It will require all ruby files in your lib folder. You just have to make sure if this is really what you want :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With