Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 not reloading code in lib while in development mode

THE SITUATION:

  1. I have code in lib/foo/bar.rb with a simple method defined as such:

    module Foo
      class Bar
        def test
          "FooBar"
        end
      end
    end
    
  2. In my helper, FooBarHelper, I have:

    require `lib/foo/bar`
    module FooBarHelper
      def test_foo_bar
        fb = Foo::Bar.new
        fb.test
      end
    end
    
  3. In my view, I call this helper method like so:

    <%= test_foo_bar =>
    
  4. In my config/environments/development.rb, I added the directory to my config.autoload_paths:

    config.autoload_paths += ["#{config.root}/lib/foo"]
    

THE PROBLEM:

When I change the return value of Foo::Bar.test to, for example, "MODIFIED FOOBAR", the original return value, "FooBar", is still being displayed on the view and not the new value.

Since I'm in development mode, shouldn't the code reload the code on every request?

Could someone tell me what I'm missing?

Thanks!

like image 609
John Avatar asked Oct 25 '10 20:10

John


1 Answers

Previous answers does not work. Here is a working one: http://ileitch.github.com/2012/03/24/rails-32-code-reloading-from-lib.html

You have to use both:

config.watchable_dirs['lib'] = [:rb]

and

require_dependency

but any config.autoload_paths based solution won't work in Rails ~> 3.2

like image 124
Mike Aski Avatar answered Nov 07 '22 13:11

Mike Aski