# Tip, may even be useful

**URL:** <https://www.ruby-forum.com/t/tip-may-even-be-useful/59813>\
**Category:** Rails\
**Created:** [May 6, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/tip-may-even-be-useful/59813 "2006-05-06T23:44:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [May 6, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/tip-may-even-be-useful/59813/1 "2006-05-06T23:44:20Z")

</div>

Here’s something that caused me a couple of hours of head-scratching  
today:

Apparently, if your model doesn’t derive from ActiveRecord, it is NOT  
reloaded for each operation in the development environment.

I was working with something that uses a single model per session, and  
stores its data in the session. I kept wondering why I didn’t see my  
changes. Finally, I changed the way I was naming a temporary file, and  
saw that it was distinctly NOT changed in the running application.

A light went on, I restarted the server, and things went much better  
after that.

I suspect there’s an easy way to force the re-loading. Anybody know what  
it is?

–Al Evans

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [May 6, 2006, 11:57pm UTC](https://www.ruby-forum.com/t/tip-may-even-be-useful/59813/2 "2006-05-06T23:57:12Z")

</div>

As stated in section C2 of the second edition of AWDR (pages 102 – 103  
of  
my brand-spanking new PDF):

“So far we’ve been enjoying the fact that Rails automatically reloads  
program files before handling each new request in development mode.  
However, that’s not the full story. In fact, Rails only reloads those  
files  
_that it knows about_ [italics in the book]. If one of our files  
subclasses  
a standard Rails class, then Rails knows about it, and manages  
appropriately  
… we can tell Rails to reload our models by including a single  
_include_  
[bold in original] directive in each.”

The illustration then adds the line “include Reloadable” in both the  
Cart  
class and the CartItem class.

“Including _Reloadable_ says ‘treat the Cart and CartItem classes as if  
they  
were like any other Rails model, and reload them before each request.’  
…  
In future, we’ll remember to add the _include Reloadable_ line in  
non-database models, and we won’t have to restart.”

There’s your answer. 🙂

Ken K.

–  
Kenneth A. Kousen, Ph.D.  
President  
Kousen IT, Inc.  
[http://www.kousenit.com](http://www.kousenit.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [May 7, 2006, 12:51am UTC](https://www.ruby-forum.com/t/tip-may-even-be-useful/59813/3 "2006-05-07T00:51:57Z")

</div>

Ken K. wrote:

> The illustration then adds the line “include Reloadable” in both the  
> Cart  
> class and the CartItem class.

you rock, I have torn some hair due to this as well.

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [May 7, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/tip-may-even-be-useful/59813/4 "2006-05-07T15:17:55Z")

</div>

Ken K. wrote:

> There’s your answer. 🙂

Thanks! I got the PDF the other day, but I’ve been too busy programming  
to look at it:-)

–Al Evans
