NoMethodError after upgrading from 1.1.6 to 1.2.3

After upgrading from Rails 1.1.6 to 1.2.3 I receive a NoMethodError when loading a particular page in my app (see Parked at Loopia). Here's what I know about it:

-The issue occurs in the development environment, but not in the production environment on the same CPU using the same database under the same server software/rails installation -If the troublesome page is loaded directly it loads the first time and throws the error on subsequent loads -If the troublesome page is loaded through a link from another page it throws an error immediately -The "q" variable does not change between lines 6 and 7 -The page executes to line 6 without error -No changes have been made to the models, controller or view involved since upgrading -The page operated normally in development and production environments under 1.1.6

What could be causing this problem?

http://pastie.caboo.se/125097

After upgrading from Rails 1.1.6 to 1.2.3 I receive a NoMethodError when loading a particular page in my app (seehttp://pastie.caboo.se/125097). Here's what I know about it:

This sounds like a dependency problem (there were a bunch of changes to that for rails 1.2). In a nutshell, between requests rails clears out all your controllers, models etc... and loads fresh ones. If that goes wrong, then you can end up with something using the old Question class (the one that rails cleared out) and shit happens. Classes aren't reloaded between requests in production, so the problem doesn't exist there.

Reasons i've seen this happen - plugins: by default these are not reloading between requests, so if a plugin holds onto a class it will get borked - requiring things 'by hand'. This bypasses the rails autoload magic and so it gets confused. Use require_dependency, or let autoloading do its magic - doing weird stuff like including a module into the top level I can't see any of this in the code you've shown, but it doesn't necessarily have to be (eg stuff in your environment.rb could do it, stuff in the editor model could do it etc... Hopefully this should point you in the right direction. The Dependencies stuff can log all the stuff it does, which can be helpful in tracking down this sort of stuff.

Fred

Fred,

That does give me some more direction. Thank you. How do I activate the dependencies logging?

Evan

Fred,

That does give me some more direction. Thank you. How do I activate the dependencies logging?

You set Dependencies.log_activity to true. In addition there are
plenty of good methods in there to pepper with extra logging. Also
checkout ActiveRecord::Base.reset_subclasses if there is a class there
that isn't being unloaded then logging there can pick that up

Fred

shouldn't it be

   has_many :advices (i.e., plural like the table name, not singular)

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

After upgrading from Rails 1.1.6 to 1.2.3 I receive a NoMethodError when loading a particular page in my app (see Parked at Loopia) . Here's what I know about it:

-The issue occurs in the development environment, but not in the production environment on the same CPU using the same database under the same server software/rails installation -If the troublesome page is loaded directly it loads the first time and throws the error on subsequent loads -If the troublesome page is loaded through a link from another page
it throws an error immediately -The "q" variable does not change between lines 6 and 7 -The page executes to line 6 without error -No changes have been made to the models, controller or view involved since upgrading -The page operated normally in development and production
environments under 1.1.6

What could be causing this problem?

Parked at Loopia

shouldn't it be

  has_many :advices (i.e., plural like the table name, not singular)

Arguably bad form, but hardly accounts for it working in production
and working in development mode the first time. You can get away with it because 'advice'.singularize == 'advice'

Fred

I agree with Rob. Seems like the problem is in the naming. I would try it with the model name 'advices', or a more straight-forward word like 'answers' or 'suggestions'. Then, you can change the view code to read "<% if q.advices.empty? %>"

good luck

Hmmm...I activated dependencies logging, but am not sure what to make of the logged activity.

http://pastie.caboo.se/125830

I have adjusted the plurality of the advice/question association in the models, controllers and views and the issue persists.

I have tried adding "require 'advice.rb'" to the Question class definition and the issue persists.

I have tried adding "require 'advice.rb'" to the Question class definition and the issue persists.

Are you sticking an entire editor object in the session? Does changing
that fix things?

Fred

Hmmm...I activated dependencies logging, but am not sure what to make of the logged activity.

Parked at Loopia

Well you can sort of see what is happening, if you compare the good
load with the bad load:

Good:

Processing EditingController#index (for 127.0.0.1 at 2007-12-06
21:11:01) [GET] Session ID: bd965b771927a6b290bbdc5018fe0364 Parameters: {"action"=>"index", "controller"=>"editing"} DEPRECATION WARNING: @session is deprecated! Call session. instead
of @session.. Args: ["editor"] See Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.   for details. (called from editor? at /Users/evan/Rails/asktheguys/ asktheguys/public/../config/../lib/editor_system.rb:87) DEPRECATION WARNING: @session is deprecated! Call session. instead
of @session.. Args: ["editor"] See Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.   for details. (called from login_required at /Users/evan/Rails/ asktheguys/asktheguys/public/../config/../lib/editor_system.rb:47) Dependencies: called load_missing_constant(Object, :Question)
Dependencies: called require_or_load("/Users/evan/Rails/asktheguys/ asktheguys/public/../config/../app/models/question.rb", nil)
Dependencies: loading /Users/evan/Rails/asktheguys/asktheguys/ public/../config/../app/models/question Dependencies: called
load_file("/Users/evan/Rails/asktheguys/asktheguys/public/../config/../ app/models/question.rb", ["Models::Question", "Question"]) Dependencies: called new_constants_in("Models", :Object) Dependencies: New constants: Question Dependencies: loading /Users/ evan/Rails/asktheguys/asktheguys/public/../config/../app/models/ question.rb defined Question Question [4;36;1mQuestion Columns (0.000593) [0m [0;1mSHOW FIELDS
FROM questions [0m [4;35;1mSQL (0.000748) [0m [0mSELECT count(*) AS
count_all FROM questions [0m [4;36;1mQuestion Load (0.000936) [0m
[0;1mSELECT * FROM questions ORDER BY questions.created_on DESC LIMIT
0, 10 [0m

Bad:

Processing EditingController#index (for 127.0.0.1 at 2007-12-06
21:11:09) [GET] Session ID: bd965b771927a6b290bbdc5018fe0364 Parameters:
{"action"=>"index", "controller"=>"editing"} DEPRECATION WARNING: @session is deprecated! Call session. instead
of @session.. Args: ["editor"] See Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.   for details. (called from editor? at /Users/evan/Rails/asktheguys/ asktheguys/public/../config/../lib/editor_system.rb:87) DEPRECATION WARNING: @session is deprecated! Call session. instead
of @session.. Args: ["editor"] See Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.   for details. (called from login_required at /Users/evan/Rails/ asktheguys/asktheguys/public/../config/../lib/editor_system.rb:47)
[4;36;1mQuestion Columns (0.001567) [0m [0;1mSHOW FIELDS FROM
questions [0m [4;35;1mSQL (0.000583) [0m [0mSELECT count(*) AS
count_all FROM questions [0m [4;36;1mQuestion Load (0.000810) [0m
[0;1mSELECT * FROM questions ORDER BY questions.created_on DESC LIMIT
0, 10 [0m See how in the first case Question is loaded from question.rb, but not
in the second case -> something is hanging on to a stale reference to
the question class, and it's something that happens in
editor_system.rb (like i said in my other mail, if you're putting an
editor object in the session, that's bad)

Fred