# Stack level too deep

**URL:** <https://www.ruby-forum.com/t/stack-level-too-deep/165768>\
**Category:** Rails\
**Created:** [April 17, 2009, 9:34am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/165768 "2009-04-17T09:34:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [April 17, 2009, 9:34am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/165768/1 "2009-04-17T09:34:25Z")

</div>

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:in`method\_missing’  
vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
249:in `method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:in`method\_missing’  
vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
249:in `method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:in`method\_missing’  
vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
249:in `method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:in`method\_missing’  
vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
249:in `method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:in`method\_missing’  
vendor/rails/activerecord/lib/active\_record/attribute\_methods.rb:  
249:in `method_missing' vendor/plugins/authorization/lib/publishare/identity.rb:106:in`method\_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:in`method\_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:in`send’  
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:in`method\_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:in`send’  
vendor/rails/actionpack/lib/action\_view/renderable.rb:39:in  
`render' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 20:in`render’  
vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
26:in `benchmark' config/environment.rb:145:in`realtime’  
vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
26:in `benchmark' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 19:in`render’  
vendor/rails/actionpack/lib/action\_view/template.rb:73:in  
`render_template' vendor/rails/actionpack/lib/action_view/renderable_partial.rb: 45:in`render\_partial’  
vendor/rails/actionpack/lib/action\_view/partials.rb:152:in  
`render_partial' vendor/rails/actionpack/lib/action_view/base.rb:258:in`render’  
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:in`render’  
vendor/rails/actionpack/lib/action\_view/template.rb:73:in  
`render_template' vendor/rails/actionpack/lib/action_view/base.rb:256:in`render’  
vendor/rails/actionpack/lib/action\_view/base.rb:367:in  
`_render_with_layout' vendor/rails/actionpack/lib/action_view/base.rb:254:in`render’  
vendor/rails/actionpack/lib/action\_controller/base.rb:1174:in  
`render_for_file' vendor/rails/actionpack/lib/action_controller/base.rb:905:in`render\_without\_benchmark’  
vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
51:in `render' config/environment.rb:145:in`realtime’  
vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:  
51:in `render' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 135:in`send’  
vendor/rails/actionpack/lib/action\_controller/mime\_responds.rb:  
135:in `custom' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 160:in`call’  
vendor/rails/actionpack/lib/action\_controller/mime\_responds.rb:  
160:in `respond' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 158:in`each’  
vendor/rails/actionpack/lib/action\_controller/mime\_responds.rb:  
158:in `respond' vendor/rails/actionpack/lib/action_controller/mime_responds.rb: 107:in`respond\_to’  
vendor/plugins/forums/lib/topic\_controller.rb:55:in `show' vendor/rails/actionpack/lib/action_controller/base.rb:1253:in`send’  
vendor/rails/actionpack/lib/action\_controller/base.rb:1253:in  
`perform_action_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:617:in`call\_filters’  
vendor/rails/actionpack/lib/action\_controller/filters.rb:610:in  
`perform_action_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 68:in`perform\_action\_without\_rescue’  
F:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 68:in`perform\_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:in`perform\_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:in`cache’  
vendor/rails/actionpack/lib/action\_controller/caching/sql\_cache.rb:  
12:in `perform_action' vendor/rails/actionpack/lib/action_controller/base.rb:524:in`send’  
vendor/rails/actionpack/lib/action\_controller/base.rb:524:in  
`process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:606:in`process\_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:in`process’  
vendor/rails/actionpack/lib/action\_controller/dispatcher.rb:183:in  
`handle_request' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in`dispatch\_unlocked’  
vendor/rails/actionpack/lib/action\_controller/dispatcher.rb:123:in  
`dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in`synchronize’  
vendor/rails/actionpack/lib/action\_controller/dispatcher.rb:122:in  
`dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in`dispatch\_cgi’  
vendor/rails/actionpack/lib/action\_controller/dispatcher.rb:39:in  
`dispatch' vendor/rails/railties/lib/webrick_server.rb:103:in`handle\_dispatch’  
vendor/rails/railties/lib/webrick\_server.rb:74:in `service' F:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in`service’  
F:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' F:/ruby/lib/ruby/1.8/webrick/server.rb:173:in`start\_thread’  
F:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' F:/ruby/lib/ruby/1.8/webrick/server.rb:162:in`start\_thread’  
F:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' F:/ruby/lib/ruby/1.8/webrick/server.rb:92:in`each’  
F:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' F:/ruby/lib/ruby/1.8/webrick/server.rb:23:in`start’  
F:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start' vendor/rails/railties/lib/webrick_server.rb:60:in`dispatch’  
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:in`require’  
vendor/rails/activesupport/lib/active\_support/dependencies.rb:  
153:in `require' vendor/rails/activesupport/lib/active_support/dependencies.rb: 521:in`new\_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:in`gem\_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

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [April 17, 2009, 9:43am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/165768/2 "2009-04-17T09:43:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [April 17, 2009, 10:02am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/165768/3 "2009-04-17T10:02:34Z")

</div>

On Apr 17, 8:42 am, Chirantan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [April 17, 2009, 12:23pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/165768/4 "2009-04-17T12:23:20Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
