3
votes

I like to keep things organized in my applications and since I have only been coding in ROR for a year. I have known how to use the app/controllers/concerns directory for custom modules to be included in a controller.

This is great however I am wondering if there is a way to add sub folders to the concerns folder to allow for better organization.

For example app/controllers/concerns/members/profile_methods.rb and the module is named 'ProfileMethods'. If I include 'ProfileMethods' RubyMine see's the module and allows me to include it, including offering it as an option in the tooltip pane. However the Rails Server says that 'ProfileMethods' is an undefined constant if it is in a sub folder of app/controllers/concerns .

Is there something I have to add to the rails application configuration? Any input would be great as it seems a little illogical that you could not further organize the concerns directory with sub folders.

1

1 Answers

4
votes

The best way to keep things organized is to name the module the following way. That way you have your code organized in both files and code itself.

module Members
  module ProfileMethods
    extend ActiveSupport::Concern 
    ... 
  end
end 

This way it will load your modules fine. Other one option is to tweak eager_load_paths in config/application.rb for instance.