Forum: Ruby on Rails problem redefining module method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Justin B. (Guest)
on 2006-01-31 01:36
(Received via mailing list)
I'm having a problem redefining a method in one of my modules. Lets
say I have this module in /lib:

module Hello
  def say_hello
    "hello"
  end
end

And one of my ActiveRecord models mixes it in like:

class Item < ActiveRecord::Base
  include Hello
end

This works fine, I can call @item.say_hello just fine. But when I try
to redefine the method:

class Item < ActiveRecord::Base
  include Hello
  def say_hello
    "Hola!"
  end
end

It only works on the first page load after restarting the server.
Every page load after that says method say_hello is undefined. I
suspect that means it has something to do with caching? But I don't
know enough about the internals to figure it out...

Thanks,
Justin
Justin B. (Guest)
on 2006-01-31 17:13
(Received via mailing list)
I got a bit farther with this. I've been having this problem in
development mode. On a whim I switched to production and it works just
fine. So I suspect it has something to do with model reloading? Is
there any way I can get around this problem in development mode?

Thanks,
Justin
Justin B. (Guest)
on 2006-01-31 18:24
(Received via mailing list)
I fixed the problem by adding:

model :hello

To any controller where that module will be used.
This topic is locked and can not be replied to.