Strange dependency error after going Ruby1.8.6, Rails 2.1.0 -> Ruby1.8.7, Rails 2.1.2

Hi,

I’m getting an error I just can’t find any cause for.
The error is “A copy of ApplicationHelper has been removed from the
module tree but is still active!” and gets thrown
in a Template that uses a method defined in my ApplicationHelper. The
error occurs only in development mode.

The error did not occur before my switch to Ruby 1.8.7 and Rails 2.1.2
minutes ago.
I have absolutely no clue about what could be causing this.
The problem occurs on windows as well as MacOS X 10.5

Any help would be appreciated.

regards

Jan

Stacktrace:

ActionView::TemplateError (A copy of ApplicationHelper has been
removed from the module tree but is still active!) on line #57 of
photosessions/show.html.erb:
54:
55:


56:
57: <%=
price_options_for(@photosession.typ) %>
58:
59:
60:
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/

active_support/dependencies.rb:250:in load_missing_constant' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/ active_support/dependencies.rb:468:inconst_missing’
app/helpers/application_helper.rb:20:in price_options_for' app/views/photosessions/show.html.erb:57:in_run_erb_47app47views47photosessions47show46html46erb’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/
base.rb:342:in send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/ base.rb:342:inexecute’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/
template_handlers/compilable.rb:29:in send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/ template_handlers/compilable.rb:29:inrender’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/
template.rb:35:in render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/ template.rb:22:inrender_template’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/
base.rb:248:in `render_file’

Java wrote:

I have absolutely no clue about what could be causing this.
ActionView::TemplateError (A copy of ApplicationHelper has been

/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/

active_support/dependencies.rb:250:in load_missing_constant' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/ active_support/dependencies.rb:468:in const_missing’
app/helpers/application_helper.rb:20:in `price_options_for’

Could you please post line 20 of application_helper.rb


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

Oh, damn, sorry, of course. I forgot, here it is:

19 def price_options_for(sessiontype)
20 options_for_select
(Price.find_all_by_sessiontype(sessiontype).map { |p|
21 ["#{p.format} #{german_price(p.price, true)}", p.format]
22 })
23 end

Other Methods in the helper never throw an exception…
After posting my original message I poked around the code a little bit
further.
I think accessing the “Price” model might cause the error.
But, uh, that’s not something that should happen, right?

Yeah, I can confirm that.
I moved the

Price.find_all_by_sessiontype(sessiontype)

out of the helper method and now everything seems to work.

I still think this error shouldn’t have happened in the first place.
I tried to investigate, but the dependency loader is so
full of Voodoo that I can’t figure it out.

Java wrote:

Yeah, I can confirm that.
I moved the

Price.find_all_by_sessiontype(sessiontype)

out of the helper method and now everything seems to work.

I still think this error shouldn’t have happened in the first place.
I tried to investigate, but the dependency loader is so
full of Voodoo that I can’t figure it out.

Yes, it shouldn’t have happened. To pinpoint the blame,
can you try downgrading one of Rails or Ruby? It’d be
easiest to set RAILS_GEM_VERSION = ‘2.1.0’ in environment.rb.


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

Ok, I tried Rails 2.1.2, 2.1.1 and 2.1.0
The error shows up in all versions.
I guess that means it has something to do with the Ruby Update (1.8.6 -

Ah, yes, thanks.

I’ll try to investigate this a bit further.
The case you linked to describes a different problem though, it seems.
In my case the model (Price) and the ApplicationHelper are fairly
vanilla,
not loading any fancy external libraries through ways untrackable by
Rails dependency mechanisms.
That’s what’s bothering me so much (after all, I got my code running
by pulling the Price reference out of the helper),
all this seems to indicate a bug somewhere in the dependency/
autoreload mechanism.

Jan

On Nov 2, 10:40 pm, Java [email protected] wrote:

Ok, I tried Rails 2.1.2, 2.1.1 and 2.1.0
The error shows up in all versions.
I guess that means it has something to do with the Ruby Update (1.8.6 -

1.8.7)?

Typically this happens when you’re mixing things that are reloading
between requests and things that aren;t (in production nothing is
reloaded so this problem can’t happen).
See
http://groups.google.com/group/rubyonrails-core/browse_thread/thread/710868b1292c737f

Fred

Well, the andand gem seems to be the culprit (http://github.com/
raganwald/andand/tree/master/lib/andand.rb).

I’ll contact the author about this.

On Nov 7, 6:22 pm, Java [email protected] wrote:

Ah, yes, thanks.

I’ll try to investigate this a bit further.
The case you linked to describes a different problem though, it seems.
In my case the model (Price) and the ApplicationHelper are fairly
vanilla,
not loading any fancy external libraries through ways untrackable by
Rails dependency mechanisms.

You can also confuse the dependency system by using require when you
could/should be using require_dependency.

That’s what’s bothering me so much (after all, I got my code running
by pulling the Price reference out of the helper),
all this seems to indicate a bug somewhere in the dependency/
autoreload mechanism.

Hard to say from what I’ve seen.

Fred

Ah, sorry, that was a little quick.
Actually the bug is caused by the resource_controller plugin.
My bad.
I posted a report in the resource_controller group.

regards

Jan