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
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 On 1/30/06, Justin Blake <jblaix@gmail.com> wrote:> 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 >
I fixed the problem by adding: model :hello To any controller where that module will be used. On 1/31/06, Justin Blake <jblaix@gmail.com> wrote:> 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 > > On 1/30/06, Justin Blake <jblaix@gmail.com> wrote: > > 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 > > >