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] %> <div class="myRequest_box"> <div class="toph"> <div id="attached_chart<%= profile.id %>" style="display:none;" class="mainC"> <%#= current_user ? (render :partial=>'/profile/ chart_partial', :locals => {:profile => profile}) : "Please <a href=\"/ \">login</a> to view the chart." -%> </div> </div> </div> <% 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: <p><b>Topic Attachments</b></p> 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: <div class="myRequest_box">
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