Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

ruby on rails - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...