# Refreshing a page gives a "stack level too deep" error.

**URL:** <https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263>\
**Category:** rubyonrails-talk\
**Created:** [March 13, 2008, 4:18pm UTC](https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263 "2008-03-13T16:18:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 13, 2008, 4:18pm UTC](https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263/1 "2008-03-13T16:18:28Z")

</div>

I'm converting our app into restful rails. A couple of my classes (Resource and Asset) have a has\_many relationship with each other - here's the routes:

&nbsp;&nbsp;&nbsp;map.resources :assets, :has\_many=\>[:resources] &nbsp;&nbsp;&nbsp;map.resources :resources, :has\_many=\>[:assets]

I'm getting something weird in my view pages. When i go to

/resources/4/assets

it works. I go to the page again (just hitting enter in the address bar) and i get the error below. I restart mongrel and it works again. Refresh again and it breaks again: every time. I can go to a different url (eg /resources/4) and its fine: come back and its broken again. My colleague, running the same code on his mac (i'm using ubuntu linux) doesn't get the error.

Has anyone seen anything like this before? I've only got it since we started using restful rails. I've tried rebooting. I've tried running webrick instead of mongrel. No joy...

Here's the trace: it seems like it has an issue with my nested path helper, "resource\_asset\_path".

Showing assets/index.html.erb where line #13 raised:

stack level too deep

Extracted source (around line #13):

10: \<tr\> 11: \<td\>\<%=h asset.name %\>\</td\> 12: \<td\>\<%=h asset.description %\>\</td\> 13: \<td\>\<%= link\_to 'Show', resource\_asset\_path(@resource, asset) %\>\</td\> 14: \<td\>\<%= link\_to 'Edit', edit\_asset\_path(asset) %\>\</td\> 15: \<td\>\<%= link\_to 'Destroy', resource\_asset\_path(@resource, asset), :confirm =\> 'Are you sure?', :method =\> :delete %\>\</td\> 16: \</tr\>

RAILS\_ROOT: /home/jars/rails/lesson\_planner/branches/bundles Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/attribute\_methods.rb:186:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:194:in `method\_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/base.rb:1948:in `to_param' (eval):2:in `resource\_asset\_path' app/views/assets/index.html.erb:13:in `_run_erb_47app47views47assets47index46html46erb' app/views/assets/index.html.erb:9:in `\_run\_erb\_47app47views47assets47index46html46erb' /usr/bin/mongrel\_rails:19:in `load' /usr/bin/mongrel\_rails:19

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 13, 2008, 4:31pm UTC](https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263/2 "2008-03-13T16:31:59Z")

</div>

"stack level to deep" sounds like something running into an infinite recursion. maybe those has\_many relations in the routes or you redirect the action to itself... first thing i would try is remove those has\_many from the routes

sorry, just some ideas without realy knowing what's going on

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 13, 2008, 4:47pm UTC](https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263/3 "2008-03-13T16:47:58Z")

</div>

Thorsten Mueller wrote:

> "stack level to deep" sounds like something running into an infinite recursion. maybe those has\_many relations in the routes or you redirect the action to itself... first thing i would try is remove those has\_many from the routes
> 
> sorry, just some ideas without realy knowing what's going on

That's what i thought, i've seen it before when writing recursive methods and not bottoming out properly. The weirdness is

a) why does it work the first time and crash when i refresh b) why does it work for someone else and not me when he has the same revision of our project?

If it take out the has\_many, and just have normal routes, then the urls don't work: i can manually put them in like so:

&nbsp;&nbsp;map.resources :assets &nbsp;&nbsp;map.resources :resources

&nbsp;&nbsp;map.connect 'resources', :controller =\> 'resources' &nbsp;&nbsp;map.connect 'resources/:id', :controller =\> 'resources' &nbsp;&nbsp;map.connect 'resources/:resource\_id/assets', :controller =\> 'assets' &nbsp;&nbsp;map.connect 'resources/:resource\_id/assets/:id', :controller =\> 'assets'

But then the helpers don't work...i'd rather have working nested resources tbh. Thanks for looking though...

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 13, 2008, 4:55pm UTC](https://discuss.rubyonrails.org/t/refreshing-a-page-gives-a-stack-level-too-deep-error/26263/4 "2008-03-13T16:55:53Z")

</div>

Max Williams wrote:

> Thorsten Mueller wrote:
> 
> > "stack level to deep" sounds like something running into an infinite recursion. maybe those has\_many relations in the routes or you redirect the action to itself... first thing i would try is remove those has\_many from the routes
> > 
> > sorry, just some ideas without realy knowing what's going on
> 
> That's what i thought, i've seen it before when writing recursive methods and not bottoming out properly. The weirdness is
> 
> a) why does it work the first time and crash when i refresh b) why does it work for someone else and not me when he has the same revision of our project?
> 
> If it take out the has\_many, and just have normal routes, then the urls don't work: i can manually put them in like so:
> 
> &nbsp;&nbsp;map.resources :assets &nbsp;&nbsp;map.resources :resources
> 
> &nbsp;&nbsp;map.connect 'resources', :controller =\> 'resources' &nbsp;&nbsp;map.connect 'resources/:id', :controller =\> 'resources' &nbsp;&nbsp;map.connect 'resources/:resource\_id/assets', :controller =\> 'assets' &nbsp;&nbsp;map.connect 'resources/:resource\_id/assets/:id', :controller =\> 'assets'
> 
> But then the helpers don't work...i'd rather have working nested resources tbh. Thanks for looking though...

I take it back, i took out this line and it's fine: &nbsp;&nbsp;map.resources :assets, has\_many =\> [:resources]

This is ok for us as we never need to do a nested assets/:asset\_id/resources call in the url.

What made me put it in originally was the fact that an asset :has\_many =\> resources, but that can happily live in the model, and i can still say things like @asset.resources in our code.

I guess the lesson is that routes should be there for a reason, rather than blindly mirroring the model associations.

cheers! max
