Adding a directory to the load path in Rails?










62















As of Rails 2.3, what's the right way to add a directory to the load path so that it hooks into Rails' auto-reloading mechanisms?



The specific example I'm thinking of is I have a class that has several sub-classes using STI and I thought it would be a good idea to put them in a sub-directory rather than clutter the top-level. So I would have something like:



#app/models/widget.rb
class Widget < ActiveRecord::Base
add_to_load_path File.join(File.dirname(__FILE__), "widgets")
end

#app/models/widgets/bar_widget.rb
class BarWidget < Widget
end

#app/models/widgets/foo_widget.rb
class FooWidget < Widget
end


It's the add_to_load_path method that I'm looking for.










share|improve this question




























    62















    As of Rails 2.3, what's the right way to add a directory to the load path so that it hooks into Rails' auto-reloading mechanisms?



    The specific example I'm thinking of is I have a class that has several sub-classes using STI and I thought it would be a good idea to put them in a sub-directory rather than clutter the top-level. So I would have something like:



    #app/models/widget.rb
    class Widget < ActiveRecord::Base
    add_to_load_path File.join(File.dirname(__FILE__), "widgets")
    end

    #app/models/widgets/bar_widget.rb
    class BarWidget < Widget
    end

    #app/models/widgets/foo_widget.rb
    class FooWidget < Widget
    end


    It's the add_to_load_path method that I'm looking for.










    share|improve this question


























      62












      62








      62


      17






      As of Rails 2.3, what's the right way to add a directory to the load path so that it hooks into Rails' auto-reloading mechanisms?



      The specific example I'm thinking of is I have a class that has several sub-classes using STI and I thought it would be a good idea to put them in a sub-directory rather than clutter the top-level. So I would have something like:



      #app/models/widget.rb
      class Widget < ActiveRecord::Base
      add_to_load_path File.join(File.dirname(__FILE__), "widgets")
      end

      #app/models/widgets/bar_widget.rb
      class BarWidget < Widget
      end

      #app/models/widgets/foo_widget.rb
      class FooWidget < Widget
      end


      It's the add_to_load_path method that I'm looking for.










      share|improve this question
















      As of Rails 2.3, what's the right way to add a directory to the load path so that it hooks into Rails' auto-reloading mechanisms?



      The specific example I'm thinking of is I have a class that has several sub-classes using STI and I thought it would be a good idea to put them in a sub-directory rather than clutter the top-level. So I would have something like:



      #app/models/widget.rb
      class Widget < ActiveRecord::Base
      add_to_load_path File.join(File.dirname(__FILE__), "widgets")
      end

      #app/models/widgets/bar_widget.rb
      class BarWidget < Widget
      end

      #app/models/widgets/foo_widget.rb
      class FooWidget < Widget
      end


      It's the add_to_load_path method that I'm looking for.







      ruby-on-rails ruby






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 3 '09 at 18:14









      Simone Carletti

      146k35311334




      146k35311334










      asked Aug 3 '09 at 17:11









      pjb3pjb3

      4,03821936




      4,03821936






















          8 Answers
          8






          active

          oldest

          votes


















          107














          In the current version of Rails (3.2.8), this has been changed in the application.rb file.



          The code is currently commented out as:



           # Custom directories with classes and modules you want to be autoloadable.
          # config.autoload_paths += %W(#config.root/extras)


          Will need to update the autoload_paths value. Attempting to modify the the former load_paths variable causes this error.



          /configuration.rb:85:in `method_missing': undefined method `load_paths' for #<Rails::Application::Configuration:0xac670b4> (NoMethodError)


          for an example, for each path to add to autoload_paths config, add a line similar to the following:



          config.autoload_paths += %W(#config.root/app/validators)



          config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.



          http://guides.rubyonrails.org/configuring.html




          From commentor (hakunin) below:



          If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.






          share|improve this answer




















          • 80





            Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

            – Jamel Toms
            Oct 16 '12 at 1:22







          • 23





            @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

            – Nick
            Nov 28 '12 at 1:31






          • 13





            for the record I am very glad this response was posted. The accepted answer is no longer correct.

            – Xavier Shay
            Jan 14 '13 at 1:20






          • 7





            If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

            – Max Chernyak
            Sep 9 '13 at 11:45






          • 3





            For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

            – Raf
            Dec 14 '14 at 23:52



















          60














          For older versions of Rails:



          You can do this in your environment.rb config file.



          config.load_paths << "#RAILS_ROOT/app/widgets"


          --



          For Rails 3, see answers bellow






          share|improve this answer




















          • 9





            ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

            – Akshay Rawat
            Nov 21 '10 at 7:15






          • 1





            See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

            – micapam
            Oct 10 '13 at 2:38


















          27














          In Rails 3, you can set this in config/application.rb, where this sample is provided by default:



          # Add additional load paths for your own custom dirs
          # config.load_paths += %W( #config.root/extras )





          share|improve this answer




















          • 13





            # config.autoload_paths += %W(#config.root/extras)

            – tamersalama
            Nov 2 '10 at 19:05


















          13














          In Rails 5 you don't have to explicitly load folders from within the app directory anymore. All folders placed inside are directly available. You don't have to touch any of the config files. But it seems as if there are some issues with Spring.



          The new workflow therefore is:



          1. create a new folder and class inside the /app directory

          2. run spring stop on the command line

          3. check the autoload-paths with bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths' on the command line. The new folder should now be listed.

          4. run spring start on the command line





          share|improve this answer

























          • I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

            – Mirv - Matt
            Mar 2 '17 at 20:39












          • @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

            – Peter Piper
            Mar 3 '17 at 9:14











          • Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

            – Mirv - Matt
            Mar 3 '17 at 12:48



















          10














          On Rails 5 you need to add the following code to environment.rb:



          # Add the widgets folder to the autoload path
          Rails.application.configure do
          config.autoload_paths << "#Rails.root/app/widgets"
          end





          share|improve this answer


















          • 5





            Rails 5 actually autoloads all folders in the app directory.

            – Peter Piper
            Feb 15 '17 at 16:46











          • Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

            – Tiago Franco
            Feb 16 '17 at 17:54


















          8














          Another update for rails 3 -- activesupport 3.0.0:



          Instead of:



          ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"


          You may need to do this:



          ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"





          share|improve this answer




















          • 2





            Rails.root is necessary in Rails 3 instead of RAILS_ROOT

            – Jack Kinsella
            Feb 16 '11 at 11:31












          • Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

            – Asif Sheikh
            Apr 29 '11 at 3:11



















          1














          I found I needed to do this after config block-- no access to config object anymore.



          This did the trick



          ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"





          share|improve this answer






























            1














            In config/application.rb add config.autoload_paths << "#config.root/models/widgets".



            File should look like this:



            module MyApp
            class Application < Rails::Application
            config.autoload_paths << "#config.root/models/widgets"
            end
            end


            I know this works for Rails 4 and 5. Probably others as well.






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1223481%2fadding-a-directory-to-the-load-path-in-rails%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              107














              In the current version of Rails (3.2.8), this has been changed in the application.rb file.



              The code is currently commented out as:



               # Custom directories with classes and modules you want to be autoloadable.
              # config.autoload_paths += %W(#config.root/extras)


              Will need to update the autoload_paths value. Attempting to modify the the former load_paths variable causes this error.



              /configuration.rb:85:in `method_missing': undefined method `load_paths' for #<Rails::Application::Configuration:0xac670b4> (NoMethodError)


              for an example, for each path to add to autoload_paths config, add a line similar to the following:



              config.autoload_paths += %W(#config.root/app/validators)



              config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.



              http://guides.rubyonrails.org/configuring.html




              From commentor (hakunin) below:



              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.






              share|improve this answer




















              • 80





                Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

                – Jamel Toms
                Oct 16 '12 at 1:22







              • 23





                @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

                – Nick
                Nov 28 '12 at 1:31






              • 13





                for the record I am very glad this response was posted. The accepted answer is no longer correct.

                – Xavier Shay
                Jan 14 '13 at 1:20






              • 7





                If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

                – Max Chernyak
                Sep 9 '13 at 11:45






              • 3





                For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

                – Raf
                Dec 14 '14 at 23:52
















              107














              In the current version of Rails (3.2.8), this has been changed in the application.rb file.



              The code is currently commented out as:



               # Custom directories with classes and modules you want to be autoloadable.
              # config.autoload_paths += %W(#config.root/extras)


              Will need to update the autoload_paths value. Attempting to modify the the former load_paths variable causes this error.



              /configuration.rb:85:in `method_missing': undefined method `load_paths' for #<Rails::Application::Configuration:0xac670b4> (NoMethodError)


              for an example, for each path to add to autoload_paths config, add a line similar to the following:



              config.autoload_paths += %W(#config.root/app/validators)



              config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.



              http://guides.rubyonrails.org/configuring.html




              From commentor (hakunin) below:



              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.






              share|improve this answer




















              • 80





                Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

                – Jamel Toms
                Oct 16 '12 at 1:22







              • 23





                @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

                – Nick
                Nov 28 '12 at 1:31






              • 13





                for the record I am very glad this response was posted. The accepted answer is no longer correct.

                – Xavier Shay
                Jan 14 '13 at 1:20






              • 7





                If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

                – Max Chernyak
                Sep 9 '13 at 11:45






              • 3





                For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

                – Raf
                Dec 14 '14 at 23:52














              107












              107








              107







              In the current version of Rails (3.2.8), this has been changed in the application.rb file.



              The code is currently commented out as:



               # Custom directories with classes and modules you want to be autoloadable.
              # config.autoload_paths += %W(#config.root/extras)


              Will need to update the autoload_paths value. Attempting to modify the the former load_paths variable causes this error.



              /configuration.rb:85:in `method_missing': undefined method `load_paths' for #<Rails::Application::Configuration:0xac670b4> (NoMethodError)


              for an example, for each path to add to autoload_paths config, add a line similar to the following:



              config.autoload_paths += %W(#config.root/app/validators)



              config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.



              http://guides.rubyonrails.org/configuring.html




              From commentor (hakunin) below:



              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.






              share|improve this answer















              In the current version of Rails (3.2.8), this has been changed in the application.rb file.



              The code is currently commented out as:



               # Custom directories with classes and modules you want to be autoloadable.
              # config.autoload_paths += %W(#config.root/extras)


              Will need to update the autoload_paths value. Attempting to modify the the former load_paths variable causes this error.



              /configuration.rb:85:in `method_missing': undefined method `load_paths' for #<Rails::Application::Configuration:0xac670b4> (NoMethodError)


              for an example, for each path to add to autoload_paths config, add a line similar to the following:



              config.autoload_paths += %W(#config.root/app/validators)



              config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.



              http://guides.rubyonrails.org/configuring.html




              From commentor (hakunin) below:



              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 4 '17 at 19:16

























              answered Oct 10 '12 at 18:44









              Jamel TomsJamel Toms

              3,18222024




              3,18222024







              • 80





                Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

                – Jamel Toms
                Oct 16 '12 at 1:22







              • 23





                @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

                – Nick
                Nov 28 '12 at 1:31






              • 13





                for the record I am very glad this response was posted. The accepted answer is no longer correct.

                – Xavier Shay
                Jan 14 '13 at 1:20






              • 7





                If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

                – Max Chernyak
                Sep 9 '13 at 11:45






              • 3





                For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

                – Raf
                Dec 14 '14 at 23:52













              • 80





                Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

                – Jamel Toms
                Oct 16 '12 at 1:22







              • 23





                @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

                – Nick
                Nov 28 '12 at 1:31






              • 13





                for the record I am very glad this response was posted. The accepted answer is no longer correct.

                – Xavier Shay
                Jan 14 '13 at 1:20






              • 7





                If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

                – Max Chernyak
                Sep 9 '13 at 11:45






              • 3





                For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

                – Raf
                Dec 14 '14 at 23:52








              80




              80





              Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

              – Jamel Toms
              Oct 16 '12 at 1:22






              Bro, you know the search engine Google, it lists 3 year old search results-all the time. Wouldn't it be nice if the 3 year old result could answer your question and end your quest sooner?

              – Jamel Toms
              Oct 16 '12 at 1:22





              23




              23





              @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

              – Nick
              Nov 28 '12 at 1:31





              @Bassetassen - StackOverflow is intended to be a repository of question and answers that are relevant and applicable at all times. When things change (ie. version updates), answers should be updated appropriately or new answers given. pocket-full-of-quarters did the right thing.

              – Nick
              Nov 28 '12 at 1:31




              13




              13





              for the record I am very glad this response was posted. The accepted answer is no longer correct.

              – Xavier Shay
              Jan 14 '13 at 1:20





              for the record I am very glad this response was posted. The accepted answer is no longer correct.

              – Xavier Shay
              Jan 14 '13 at 1:20




              7




              7





              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

              – Max Chernyak
              Sep 9 '13 at 11:45





              If the directory is under app/, you don't need to add it anywhere, it should just work by default (definitely in 3.2.12). Rails has eager_load_paths that acts as autoload_paths in development, and eager load in production. All app/* directories are automatically added there.

              – Max Chernyak
              Sep 9 '13 at 11:45




              3




              3





              For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

              – Raf
              Dec 14 '14 at 23:52






              For anyone wondering, @hakunin's comment still holds true for Rails 4. Any directory added in app/* will work.

              – Raf
              Dec 14 '14 at 23:52














              60














              For older versions of Rails:



              You can do this in your environment.rb config file.



              config.load_paths << "#RAILS_ROOT/app/widgets"


              --



              For Rails 3, see answers bellow






              share|improve this answer




















              • 9





                ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

                – Akshay Rawat
                Nov 21 '10 at 7:15






              • 1





                See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

                – micapam
                Oct 10 '13 at 2:38















              60














              For older versions of Rails:



              You can do this in your environment.rb config file.



              config.load_paths << "#RAILS_ROOT/app/widgets"


              --



              For Rails 3, see answers bellow






              share|improve this answer




















              • 9





                ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

                – Akshay Rawat
                Nov 21 '10 at 7:15






              • 1





                See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

                – micapam
                Oct 10 '13 at 2:38













              60












              60








              60







              For older versions of Rails:



              You can do this in your environment.rb config file.



              config.load_paths << "#RAILS_ROOT/app/widgets"


              --



              For Rails 3, see answers bellow






              share|improve this answer















              For older versions of Rails:



              You can do this in your environment.rb config file.



              config.load_paths << "#RAILS_ROOT/app/widgets"


              --



              For Rails 3, see answers bellow







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Feb 1 '14 at 4:16









              Benj

              10.8k12458




              10.8k12458










              answered Aug 3 '09 at 17:16









              ryanbryanb

              15k44343




              15k44343







              • 9





                ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

                – Akshay Rawat
                Nov 21 '10 at 7:15






              • 1





                See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

                – micapam
                Oct 10 '13 at 2:38












              • 9





                ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

                – Akshay Rawat
                Nov 21 '10 at 7:15






              • 1





                See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

                – micapam
                Oct 10 '13 at 2:38







              9




              9





              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

              – Akshay Rawat
              Nov 21 '10 at 7:15





              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"

              – Akshay Rawat
              Nov 21 '10 at 7:15




              1




              1





              See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

              – micapam
              Oct 10 '13 at 2:38





              See answer by pocket-full-of-quarters which is actually correct. This one is now out of date.

              – micapam
              Oct 10 '13 at 2:38











              27














              In Rails 3, you can set this in config/application.rb, where this sample is provided by default:



              # Add additional load paths for your own custom dirs
              # config.load_paths += %W( #config.root/extras )





              share|improve this answer




















              • 13





                # config.autoload_paths += %W(#config.root/extras)

                – tamersalama
                Nov 2 '10 at 19:05















              27














              In Rails 3, you can set this in config/application.rb, where this sample is provided by default:



              # Add additional load paths for your own custom dirs
              # config.load_paths += %W( #config.root/extras )





              share|improve this answer




















              • 13





                # config.autoload_paths += %W(#config.root/extras)

                – tamersalama
                Nov 2 '10 at 19:05













              27












              27








              27







              In Rails 3, you can set this in config/application.rb, where this sample is provided by default:



              # Add additional load paths for your own custom dirs
              # config.load_paths += %W( #config.root/extras )





              share|improve this answer















              In Rails 3, you can set this in config/application.rb, where this sample is provided by default:



              # Add additional load paths for your own custom dirs
              # config.load_paths += %W( #config.root/extras )






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 6 '11 at 22:04









              Jared

              1,74311433




              1,74311433










              answered Sep 6 '10 at 16:51









              JacobJacob

              3,95411617




              3,95411617







              • 13





                # config.autoload_paths += %W(#config.root/extras)

                – tamersalama
                Nov 2 '10 at 19:05












              • 13





                # config.autoload_paths += %W(#config.root/extras)

                – tamersalama
                Nov 2 '10 at 19:05







              13




              13





              # config.autoload_paths += %W(#config.root/extras)

              – tamersalama
              Nov 2 '10 at 19:05





              # config.autoload_paths += %W(#config.root/extras)

              – tamersalama
              Nov 2 '10 at 19:05











              13














              In Rails 5 you don't have to explicitly load folders from within the app directory anymore. All folders placed inside are directly available. You don't have to touch any of the config files. But it seems as if there are some issues with Spring.



              The new workflow therefore is:



              1. create a new folder and class inside the /app directory

              2. run spring stop on the command line

              3. check the autoload-paths with bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths' on the command line. The new folder should now be listed.

              4. run spring start on the command line





              share|improve this answer

























              • I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

                – Mirv - Matt
                Mar 2 '17 at 20:39












              • @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

                – Peter Piper
                Mar 3 '17 at 9:14











              • Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

                – Mirv - Matt
                Mar 3 '17 at 12:48
















              13














              In Rails 5 you don't have to explicitly load folders from within the app directory anymore. All folders placed inside are directly available. You don't have to touch any of the config files. But it seems as if there are some issues with Spring.



              The new workflow therefore is:



              1. create a new folder and class inside the /app directory

              2. run spring stop on the command line

              3. check the autoload-paths with bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths' on the command line. The new folder should now be listed.

              4. run spring start on the command line





              share|improve this answer

























              • I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

                – Mirv - Matt
                Mar 2 '17 at 20:39












              • @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

                – Peter Piper
                Mar 3 '17 at 9:14











              • Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

                – Mirv - Matt
                Mar 3 '17 at 12:48














              13












              13








              13







              In Rails 5 you don't have to explicitly load folders from within the app directory anymore. All folders placed inside are directly available. You don't have to touch any of the config files. But it seems as if there are some issues with Spring.



              The new workflow therefore is:



              1. create a new folder and class inside the /app directory

              2. run spring stop on the command line

              3. check the autoload-paths with bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths' on the command line. The new folder should now be listed.

              4. run spring start on the command line





              share|improve this answer















              In Rails 5 you don't have to explicitly load folders from within the app directory anymore. All folders placed inside are directly available. You don't have to touch any of the config files. But it seems as if there are some issues with Spring.



              The new workflow therefore is:



              1. create a new folder and class inside the /app directory

              2. run spring stop on the command line

              3. check the autoload-paths with bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths' on the command line. The new folder should now be listed.

              4. run spring start on the command line






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Feb 24 '17 at 13:01

























              answered Feb 15 '17 at 17:01









              Peter PiperPeter Piper

              1,29011631




              1,29011631












              • I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

                – Mirv - Matt
                Mar 2 '17 at 20:39












              • @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

                – Peter Piper
                Mar 3 '17 at 9:14











              • Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

                – Mirv - Matt
                Mar 3 '17 at 12:48


















              • I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

                – Mirv - Matt
                Mar 2 '17 at 20:39












              • @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

                – Peter Piper
                Mar 3 '17 at 9:14











              • Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

                – Mirv - Matt
                Mar 3 '17 at 12:48

















              I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

              – Mirv - Matt
              Mar 2 '17 at 20:39






              I am finding this one unreliable & I never had spring installed or in my gemfile (when executed). By unreliable I mean the puts code finds the directory but none of the files in it are loaded to include elsewhere. Including classes does work for me when I put the autoload_path in the config/application.rb instead.

              – Mirv - Matt
              Mar 2 '17 at 20:39














              @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

              – Peter Piper
              Mar 3 '17 at 9:14





              @Mirv - which rails version are you on? and have a look at: guides.rubyonrails.org/…

              – Peter Piper
              Mar 3 '17 at 9:14













              Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

              – Mirv - Matt
              Mar 3 '17 at 12:48






              Yea, I read those & then tested on rails 5.0.0 & 5.1.0 in cloud9's IDE. It apparently doesn't handle like normal changes to the files when running rails s, but instead I have to reload! while in rails c, which isn't mentioned for 3 more sections of the documentation! I went back & checked, right now as it stands for my project - I have to manually add the file even though it's located in app/classes/filler.rb while using rails c ... I even restarted the workspace, though I haven't started a completely fresh project.

              – Mirv - Matt
              Mar 3 '17 at 12:48












              10














              On Rails 5 you need to add the following code to environment.rb:



              # Add the widgets folder to the autoload path
              Rails.application.configure do
              config.autoload_paths << "#Rails.root/app/widgets"
              end





              share|improve this answer


















              • 5





                Rails 5 actually autoloads all folders in the app directory.

                – Peter Piper
                Feb 15 '17 at 16:46











              • Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

                – Tiago Franco
                Feb 16 '17 at 17:54















              10














              On Rails 5 you need to add the following code to environment.rb:



              # Add the widgets folder to the autoload path
              Rails.application.configure do
              config.autoload_paths << "#Rails.root/app/widgets"
              end





              share|improve this answer


















              • 5





                Rails 5 actually autoloads all folders in the app directory.

                – Peter Piper
                Feb 15 '17 at 16:46











              • Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

                – Tiago Franco
                Feb 16 '17 at 17:54













              10












              10








              10







              On Rails 5 you need to add the following code to environment.rb:



              # Add the widgets folder to the autoload path
              Rails.application.configure do
              config.autoload_paths << "#Rails.root/app/widgets"
              end





              share|improve this answer













              On Rails 5 you need to add the following code to environment.rb:



              # Add the widgets folder to the autoload path
              Rails.application.configure do
              config.autoload_paths << "#Rails.root/app/widgets"
              end






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 3 '16 at 21:44









              Tiago FrancoTiago Franco

              939916




              939916







              • 5





                Rails 5 actually autoloads all folders in the app directory.

                – Peter Piper
                Feb 15 '17 at 16:46











              • Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

                – Tiago Franco
                Feb 16 '17 at 17:54












              • 5





                Rails 5 actually autoloads all folders in the app directory.

                – Peter Piper
                Feb 15 '17 at 16:46











              • Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

                – Tiago Franco
                Feb 16 '17 at 17:54







              5




              5





              Rails 5 actually autoloads all folders in the app directory.

              – Peter Piper
              Feb 15 '17 at 16:46





              Rails 5 actually autoloads all folders in the app directory.

              – Peter Piper
              Feb 15 '17 at 16:46













              Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

              – Tiago Franco
              Feb 16 '17 at 17:54





              Thanks. This was the default behaviour last time I checked, but honestly I can't remember if it was a production only issue like stated in here: blog.bigbinary.com/2016/08/29/…

              – Tiago Franco
              Feb 16 '17 at 17:54











              8














              Another update for rails 3 -- activesupport 3.0.0:



              Instead of:



              ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"


              You may need to do this:



              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"





              share|improve this answer




















              • 2





                Rails.root is necessary in Rails 3 instead of RAILS_ROOT

                – Jack Kinsella
                Feb 16 '11 at 11:31












              • Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

                – Asif Sheikh
                Apr 29 '11 at 3:11
















              8














              Another update for rails 3 -- activesupport 3.0.0:



              Instead of:



              ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"


              You may need to do this:



              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"





              share|improve this answer




















              • 2





                Rails.root is necessary in Rails 3 instead of RAILS_ROOT

                – Jack Kinsella
                Feb 16 '11 at 11:31












              • Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

                – Asif Sheikh
                Apr 29 '11 at 3:11














              8












              8








              8







              Another update for rails 3 -- activesupport 3.0.0:



              Instead of:



              ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"


              You may need to do this:



              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"





              share|improve this answer















              Another update for rails 3 -- activesupport 3.0.0:



              Instead of:



              ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"


              You may need to do this:



              ActiveSupport::Dependencies.autoload_paths << "#RAILS_ROOT/app/widgets"






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 9 '16 at 6:49









              songyy

              2,21732852




              2,21732852










              answered Oct 12 '10 at 22:51









              gdakramgdakram

              354411




              354411







              • 2





                Rails.root is necessary in Rails 3 instead of RAILS_ROOT

                – Jack Kinsella
                Feb 16 '11 at 11:31












              • Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

                – Asif Sheikh
                Apr 29 '11 at 3:11













              • 2





                Rails.root is necessary in Rails 3 instead of RAILS_ROOT

                – Jack Kinsella
                Feb 16 '11 at 11:31












              • Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

                – Asif Sheikh
                Apr 29 '11 at 3:11








              2




              2





              Rails.root is necessary in Rails 3 instead of RAILS_ROOT

              – Jack Kinsella
              Feb 16 '11 at 11:31






              Rails.root is necessary in Rails 3 instead of RAILS_ROOT

              – Jack Kinsella
              Feb 16 '11 at 11:31














              Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

              – Asif Sheikh
              Apr 29 '11 at 3:11






              Under Rails 3.0.3, I had to use ActiveSupport::Dependencies.autoload_paths += %W( #Rails.root.to_s/app/libs )

              – Asif Sheikh
              Apr 29 '11 at 3:11












              1














              I found I needed to do this after config block-- no access to config object anymore.



              This did the trick



              ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"





              share|improve this answer



























                1














                I found I needed to do this after config block-- no access to config object anymore.



                This did the trick



                ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"





                share|improve this answer

























                  1












                  1








                  1







                  I found I needed to do this after config block-- no access to config object anymore.



                  This did the trick



                  ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"





                  share|improve this answer













                  I found I needed to do this after config block-- no access to config object anymore.



                  This did the trick



                  ActiveSupport::Dependencies.load_paths << "#RAILS_ROOT/app/widgets"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 26 '09 at 21:30









                  Lewis HoffmanLewis Hoffman

                  111




                  111





















                      1














                      In config/application.rb add config.autoload_paths << "#config.root/models/widgets".



                      File should look like this:



                      module MyApp
                      class Application < Rails::Application
                      config.autoload_paths << "#config.root/models/widgets"
                      end
                      end


                      I know this works for Rails 4 and 5. Probably others as well.






                      share|improve this answer





























                        1














                        In config/application.rb add config.autoload_paths << "#config.root/models/widgets".



                        File should look like this:



                        module MyApp
                        class Application < Rails::Application
                        config.autoload_paths << "#config.root/models/widgets"
                        end
                        end


                        I know this works for Rails 4 and 5. Probably others as well.






                        share|improve this answer



























                          1












                          1








                          1







                          In config/application.rb add config.autoload_paths << "#config.root/models/widgets".



                          File should look like this:



                          module MyApp
                          class Application < Rails::Application
                          config.autoload_paths << "#config.root/models/widgets"
                          end
                          end


                          I know this works for Rails 4 and 5. Probably others as well.






                          share|improve this answer















                          In config/application.rb add config.autoload_paths << "#config.root/models/widgets".



                          File should look like this:



                          module MyApp
                          class Application < Rails::Application
                          config.autoload_paths << "#config.root/models/widgets"
                          end
                          end


                          I know this works for Rails 4 and 5. Probably others as well.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 12 '18 at 5:13









                          Jurgen

                          1,44321833




                          1,44321833










                          answered Oct 10 '17 at 20:33









                          TylerTyler

                          32336




                          32336



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1223481%2fadding-a-directory-to-the-load-path-in-rails%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                              Edmonton

                              Crossroads (UK TV series)