Stack level too deep

In my application there are 2 models - Profile and Topic. Profiles can
be attached to topics and hence I have a many to many relationship
between them. Things were good until recently I encountered a problem
that said “stack level too deep”. I’m using Rails 2.2.2 and Ruby 1.8.6

My controller method looks like this:

def show
@topic = Topic.find(params[:id])
@attachments = @topic.profiles
end

Looks pretty trivial.

On the view, I am iterating through the attachments and calling a
partial by sending every attachment as a local variable

My view looks like this -
<% for profile in @attachments %>
<% p profile %>
<% p profile.id %>
<% p session[:user] %>
<% onclick_expand = “expand(‘show_chart_button_#
{profile.id}’,‘attached_chart#{profile.id}’)” if session[:user] %>




<%#= current_user ? (render :partial=>’/profile/
chart_partial’, :locals => {:profile => profile}) : “Please <a href=”/
“>login to view the chart.” -%>

<% end %>

However, even before the partial is called, I get “stack level too
deep error”, on lines where I try to inspect the profile object and
its attributes, after waiting for a long time. Before inspecting the
profile object, I was getting the same error on line no. 33 (See the
log below)

My log looks like this -

ActionView::TemplateError (stack level too deep) on line #31 of app/
views/topic/attachments.html.erb:
28:

Topic Attachments


29: <% for profile in @attachments %>
30: <% p profile %>
31: <% p profile.id %>
32: <% p session[:user] %>
33: <% onclick_expand = "expand('show_chart_button
#
{profile.id}’,‘attached_chart#{profile.id}’)" if session[:user] %>
34:

vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
249:in method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:inmethod_missing’

(These entries appear in the log hundreds of times followed by
the ones below)

app/views/topic/_attachments.html.erb:31
vendor/rails/activerecord/lib/active_record/associations/

association_collection.rb:359:in method_missing_without_paginate' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:212:inmethod_missing’
vendor/rails/activerecord/lib/active_record/associations/
association_proxy.rb:212:in each' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:212:insend’
vendor/rails/activerecord/lib/active_record/associations/
association_proxy.rb:212:in method_missing' vendor/rails/activerecord/lib/active_record/associations/ association_collection.rb:359:inmethod_missing_without_paginate’
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:167:in
method_missing' app/views/topic/_attachments.html.erb:29 vendor/rails/actionpack/lib/action_view/renderable.rb:39:insend’
vendor/rails/actionpack/lib/action_view/renderable.rb:39:in
render' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 20:inrender’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
26:in benchmark' config/environment.rb:145:inrealtime’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
26:in benchmark' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 19:inrender’
vendor/rails/actionpack/lib/action_view/template.rb:73:in
render_template' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 45:inrender_partial’
vendor/rails/actionpack/lib/action_view/partials.rb:152:in
render_partial' vendor/rails/actionpack/lib/action_view/base.rb:258:inrender’
app/views/topic/show.html.erb:30
vendor/rails/actionpack/lib/action_view/renderable.rb:39:in send' vendor/rails/actionpack/lib/action_view/renderable.rb:39:inrender’
vendor/rails/actionpack/lib/action_view/template.rb:73:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:256:inrender’
vendor/rails/actionpack/lib/action_view/base.rb:367:in
_render_with_layout' vendor/rails/actionpack/lib/action_view/base.rb:254:inrender’
vendor/rails/actionpack/lib/action_controller/base.rb:1174:in
render_for_file' vendor/rails/actionpack/lib/action_controller/base.rb:905:inrender_without_benchmark’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
51:in render' config/environment.rb:145:inrealtime’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
51:in render' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 135:insend’
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:
135:in custom' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 160:incall’
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:
160:in respond' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 158:ineach’
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:
158:in respond' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 107:inrespond_to’
vendor/plugins/forums/lib/topic_controller.rb:55:in show' vendor/rails/actionpack/lib/action_controller/base.rb:1253:insend’
vendor/rails/actionpack/lib/action_controller/base.rb:1253:in
perform_action_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:617:incall_filters’
vendor/rails/actionpack/lib/action_controller/filters.rb:610:in
perform_action_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 68:inperform_action_without_rescue’
F:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 68:inperform_action_without_rescue’
vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in
perform_action_without_caching' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 13:inperform_action’
vendor/rails/activerecord/lib/active_record/connection_adapters/
abstract/query_cache.rb:34:in cache' vendor/rails/activerecord/lib/active_record/query_cache.rb:8:incache’
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:
12:in perform_action' vendor/rails/actionpack/lib/action_controller/base.rb:524:insend’
vendor/rails/actionpack/lib/action_controller/base.rb:524:in
process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:606:inprocess_without_session_management_support’
vendor/rails/actionpack/lib/action_controller/
session_management.rb:134:in process' vendor/rails/actionpack/lib/action_controller/base.rb:392:inprocess’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:183:in
handle_request' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:indispatch_unlocked’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:insynchronize’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:indispatch_cgi’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:39:in
dispatch' vendor/rails/railties/lib/webrick_server.rb:103:inhandle_dispatch’
vendor/rails/railties/lib/webrick_server.rb:74:in service' F:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
F:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' F:/ruby/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
F:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start' F:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
F:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' F:/ruby/lib/ruby/1.8/webrick/server.rb:92:ineach’
F:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' F:/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’
F:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:60:indispatch’
vendor/rails/railties/lib/commands/servers/webrick.rb:66
F:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
gem_original_require' F:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire’
vendor/rails/activesupport/lib/active_support/dependencies.rb:
153:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb: 521:innew_constants_in’
vendor/rails/activesupport/lib/active_support/dependencies.rb:
153:in require' vendor/rails/railties/lib/commands/server.rb:49 F:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require’
F:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require’
script/server:3

I have no clue about why this is happening. This is something not
complex at all and I have done it hundreds of times. Can someone
please help me out here?

Chirantan

Forgot to mention,

Once I restart the server, for the first attempt, things work. But if
try to reload the page without restarting the server. The error is
seen again.

On Apr 17, 8:42 am, Chirantan [email protected] wrote:

Forgot to mention,

Once I restart the server, for the first attempt, things work. But if
try to reload the page without restarting the server. The error is
seen again.

Does the problem only occur when config.cache_classes = false ?

If so then it’s likely a class reloading problem, by the looks of it
the Profile class has been reloaded but you’re still holding onto an
old copy of it. Possible causes of this include one of the classes
being defined in a plugin or explicitly loading a class with require
when you don’t need to (in this case i’d guess you have require
‘topic’ somewhere.

Fred

You were right, Fred. When I changed config.cache_classes to true, the
problem disappeared. Need to dig in to determine the exact cause. But
for now, since there is shortage of time and this has worked, I’m
going to stop working on this issue. But will definitely try to fix
this before the next release and post my findings here.

Thanks a lot!

C

On Apr 17, 1:00 pm, Frederick C. [email protected]