# Model not updating

**URL:** <https://www.ruby-forum.com/t/model-not-updating/110238>\
**Category:** Rails\
**Created:** [July 24, 2007, 3:19pm UTC](https://www.ruby-forum.com/t/model-not-updating/110238 "2007-07-24T15:19:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kusako](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kusako](https://www.ruby-forum.com/u/kusako)\
**Post date:** [July 24, 2007, 3:19pm UTC](https://www.ruby-forum.com/t/model-not-updating/110238/1 "2007-07-24T15:19:10Z")

</div>

Hi,

I’ve just found myself in charge of maintaining and developing a rails  
web application at my company. It’s a newbish question as I have pretty  
much no experience with rails before. The problem is that although I  
change a model file, app/models/template.rb, the web application doesn’t  
update with the change. In fact, nothing I do to the file seems to  
affect the application - I even moved it to a different directory, and  
the application still behaves as before.

The application runs with the memcached and the acts\_as\_cached plugin,  
but that particular model file isn’t specified to be cached. So, any  
tips how I can make my changes to the model file apply to the  
application?

BR /Markus

---

<div class="post-metadata">

**Author:** ![kusako](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kusako](https://www.ruby-forum.com/u/kusako)\
**Post date:** [July 24, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/model-not-updating/110238/2 "2007-07-24T16:50:54Z")

</div>

Markus SvennerstÃ¥l wrote:

> I’ve just found myself in charge of maintaining and developing a rails  
> web application at my company. It’s a newbish question as I have pretty  
> much no experience with rails before. The problem is that although I  
> change a model file, app/models/template.rb, the web application doesn’t  
> update with the change. In fact, nothing I do to the file seems to  
> affect the application - I even moved it to a different directory, and  
> the application still behaves as before.
> 
> The application runs with the memcached and the acts\_as\_cached plugin,  
> but that particular model file isn’t specified to be cached. So, any  
> tips how I can make my changes to the model file apply to the  
> application?

If you are modifying the application in production, the model class  
won’t be reloaded unless you stop and restart the server. In the  
development configuration of the Rails environment, model classes (and  
many others) are automatically reloaded when they change.

Now, if you are modifying the application code on the production server,  
you have a whole other mess of problems to deal with. You really need to  
study up on best practices for server development and maintenance. At a  
minimum you need to develop on a machine that isn’t your production  
server, store your code in a versioned repository such as Subversion,  
and deploy only a tested revision to production. Anything less is  
eventually going to end up with you in a lot of pain.

If you are already doing allnthat, then perhaps your development  
environment somehow thinks it is a production one. Look in  
config.environment.rb near the top of the file and see if the line  
ENV[‘RAILS\_ENV’] ||= ‘production’  
is active. Commenting it out might fix things for you. If that doesn’t  
help, maybe you are using a script that is setting RAILS\_ENV to  
production. Or the previous developer may have hacked the code in some  
way that disables class reloading. In the file  
config/environments/development.rb, there should be a line that says  
config.cache\_classes = false  
If that isn’t there or sets it to true, fix it.

Good luck.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![kusako](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kusako](https://www.ruby-forum.com/u/kusako)\
**Post date:** [July 24, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/model-not-updating/110238/3 "2007-07-24T18:15:49Z")

</div>

Markus SvennerstÃ¥l wrote:

> Hi,
> 
> I’ve just found myself in charge of maintaining and developing a rails  
> web application at my company. It’s a newbish question as I have pretty  
> much no experience with rails before. The problem is that although I  
> change a model file, app/models/template.rb, the web application doesn’t  
> update with the change. In fact, nothing I do to the file seems to  
> affect the application - I even moved it to a different directory, and  
> the application still behaves as before.

Markus,

Also keep in mind that only ActiveRecord::Base descendants (in Rails 1.1  
at least) are reloaded automatically. If you model doesn’t extend  
ActiveRecord::Base, maybe it isn’t getting reloaded automatically. I’m  
not sure if that behavior still exists in Rails 1.2, since I know that  
they modified the reloading behavior in Rails 1.2.

Wes

---

<div class="post-metadata">

**Author:** ![kusako](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kusako](https://www.ruby-forum.com/u/kusako)\
**Post date:** [July 26, 2007, 11:33am UTC](https://www.ruby-forum.com/t/model-not-updating/110238/4 "2007-07-26T11:33:14Z")

</div>

Wes G. wrote:

> Markus SvennerstÃ¥l wrote:
> 
> > Hi,
> > 
> > I’ve just found myself in charge of maintaining and developing a rails  
> > web application at my company. It’s a newbish question as I have pretty  
> > much no experience with rails before. The problem is that although I  
> > change a model file, app/models/template.rb, the web application doesn’t  
> > update with the change. In fact, nothing I do to the file seems to  
> > affect the application - I even moved it to a different directory, and  
> > the application still behaves as before.
> 
> Markus,
> 
> Also keep in mind that only ActiveRecord::Base descendants (in Rails 1.1  
> at least) are reloaded automatically. If you model doesn’t extend  
> ActiveRecord::Base, maybe it isn’t getting reloaded automatically. I’m  
> not sure if that behavior still exists in Rails 1.2, since I know that  
> they modified the reloading behavior in Rails 1.2.
> 
> Wes

Hi, thanks to both of you for the helpful answers.

I have set up a development environment - but it was running in  
production mode, so that was the core of the problem. Changed it to  
development mode, and now it works much better.

As for how to properly handle server development and maintenance, I have  
some vague ideas about how it should be done. Right now I have two  
environments - a production environment and a development environment.  
I’m currently trying to get the old CVS repository working; in the  
meanwhile I’ll just use a script to manually migrate my changes and  
create restore points whenever I do so.

One question though: I run my development and production servers as  
different virtual hosts on the same apache server. It’s been working  
fine so far, but is there any inherent dangers with that setup, like the  
development server crashing / hanging the web server?

Many thanks /Markus

---

<div class="post-metadata">

**Author:** ![kusako](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kusako](https://www.ruby-forum.com/u/kusako)\
**Post date:** [July 26, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/model-not-updating/110238/5 "2007-07-26T17:58:34Z")

</div>

Markus SvennerstÃ¥l wrote:

> One question though: I run my development and production servers as  
> different virtual hosts on the same apache server. It’s been working  
> fine so far, but is there any inherent dangers with that setup, like the  
> development server crashing / hanging the web server?

I wouldn’t think so, although I don’t claim to be an expert in this  
realm. But however you deploy, your development and production servers  
will definitely be running your Rails app in completely separate Ruby  
processes so they won’t hurt the Apache server.

If you do something that hangs/brings down the entire box, then of  
course, you will affect both environments.

Wes
