THE SITUATION:
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
In my helper, FooBarHelper
, I have:
require `lib/foo/bar`
module FooBarHelper
def test_foo_bar
fb = Foo::Bar.new
fb.test
end
end
In my view, I call this helper method like so:
<%= test_foo_bar =>
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With