I am getting a method_missing error when I run my application in the
production environment unless I set config.cache_classes = false in
config/environments/production.rb. This happens in Rails 2.2.2 but not
in Rails 2.1.0. The method that is missing is one I used to have
before I edited by hand the migration that creates the table
associated with the object (I know you are discouraged to do this, but
I had started with a very simple model and thought it would be cleaner
to have the bulk of the data defined in the first migration). I wonder
if this has anything to do with the issue.
t.timestamps
end
add_index(:clients, :name, :unique=>true)
end
into
def self.up
create_table :clients do |t|
t.string :last_name, :null=>false
t.string :first_name, :null=>false
t.text :office_address
t.text :home_address
<bunch of other fields>
t.timestamps
end
add_index(:clients, :last_name, :unique=>true)
end
I then ran "rake db:migrate VERSION=0" and then "rake db:migrate"
All worked fine in both development and production environments in
Rails 2.1.0, but broke in Rails 2.2.2/production with the message
"undefined method `name' for #<Client:0xb72d361c>"
From what I can tell, with the object cache enabled, Rails thinks that
the Client object still has a method called name (which it used to
have). I wonder how persistent is the object cache (I'd imagine not
across server restarts) or if the source of this problem is elsewhere.
All worked fine in both development and production environments in
Rails 2.1.0, but broke in Rails 2.2.2/production with the message
"undefined method `name' for #<Client:0xb72d361c>"
When does this error occur - what's the stack trace ?
This happens when trying to save the Client object, here is the
stack
trace
Looks like you still have a validation against name.
Fred
That seems to be the case, but why? Why does it happen only with
cache_classes = true? It seems to me that the cache is not being
flushed...
Without seeing any code it's hard to say. One extra thing that happens
in 2.2 when cache_classes is true is that models are loaded when the
server starts up (previously they were loaded on demand). This can
mean that faulty code that was never loaded before is now loaded.
Well, it turns out that I had left in app/models a renamed version of
the previous Client model file (client--previous.rb) which was
throwing things off. After I removed the file all worked as expected.
Thanks all for your help, and sorry for the red herring.