views:

105

answers:

2

I've added an "account" variable to a Rails app I'm running, and tested in the development environment with a mongrel server. Everything worked fine. I set my environment to production and use our Apache server, and suddenly nothing works. After a lot of debugging, I've found that the account variable is succesfullying being SET in my methods, but it's not SAVING (that is, once it gets out of the method that sets it, it's nil). I can call save or save! as many times as I want, and it's still not being set.

The attribute is accessible, and I'm not seeing any errors in the logs... It's just not saving.

Any idea what's going on?

-Jenny

+2  A: 

Ah, I migrated to dev, but not production. I didn't think it could be the migrations, because if it were, I reasoned, I wouldn't be able to access @video.account, or whatever, because I would get a "method does not exist" error (which is what I was getting before I migrated in dev).

Jenny
A: 

A bit more information to help you out on why that happened:

Check out the file db/schema.rb - it contains a Ruby representation of your database, updated on each migration. Models in Rails base their attributes on this file.

So when you migrate in development mode, the schema file is updated. When you move to production mode, that file is kept, and Rails doesn't know that the columns you are trying to assign don't exist. As such, the object you update accepts the attribute assignment, sends the query, and moves on - not noticing that the attribute didn't really save.

That's my understanding of it - hope this helps you in your quest!

Matchu