Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>TL;DR</strong></p> <ul> <li><p>put this in <em>config/application.rb</em></p> <p><code>config.eager_load_paths += ["#{Rails.root}/lib"]</code></p></li> <li><p>remove <code>require</code> statements for your <em>lib</em> files</p></li> </ul> <p>Go!</p> <hr> <p>Let me explain in detail.</p> <p>I don't know why this answer is accepted, since it doesn't help with <strong>reloading lib folder on each request</strong>. First I thought that it works for Rails 2, but the question clearly states that it was for Rails 3 and the release date of 3.0.0 is before the date of the answer.</p> <p>Other answers seem over-complicated or don't provide a real solution.</p> <p>I decided to investigate things a little, because it was bothering me and I've even found out that people have a workaround for this and it involves saving lib files inside <code>app/models</code> in development and then moving it to <code>/lib</code> when done. We can do better, right?</p> <hr> <p>My solution is tested against:</p> <ul> <li>Rails 3.0.20</li> <li>Rails 3.1.12</li> <li>Rails 3.2.13</li> <li>Rails 4.0.0.rc1</li> </ul> <p>Put this into your <code>config/application.rb</code>:</p> <pre><code># in config/application.rb config.eager_load_paths += ["#{Rails.root}/lib"] </code></pre> <p><em>That's it!™</em></p> <p>Make sure you put it here since it will <strong>not work</strong> if you put it in <code>config/environments/development.rb</code>, for example.</p> <p>Make sure your remove all the <code>require</code> statements for your <code>/lib</code> code since <code>require</code> statements will also cause this solution to not work.</p> <hr> <p>This code implicitly requires your code, so if you do environment checks (which are unnecessary) and instead of the above code, you decide to write something like this:</p> <pre><code># in config/application.rb config.eager_load_paths += ["#{Rails.root}/lib"] if Rails.env.development? </code></pre> <p>you should watch out on the old <code>require</code> statements, since they are still required on all the non-development environments, in this scenario.</p> <p>So if you still decide to do environment checks, make sure you do inverse checks for require statements. Otherwise you'll get bitten!</p> <pre><code>require "beer_creator" unless Rails.env.development? </code></pre> <p>You might think that writing entire paragraph about something that's unnecessary is also unnecessary, but I think that warning people about something that's necessary when doing something unnecessary is also necessary.</p> <p>If you would like to know more about this topic, check out <a href="https://gist.github.com/shime/6696842" rel="nofollow noreferrer">this little tutorial</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload