# Stack level too deep

**URL:** <https://www.ruby-forum.com/t/stack-level-too-deep/108515>\
**Category:** Rails\
**Created:** [July 4, 2007, 10:45am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515 "2007-07-04T10:45:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 10:45am UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/1 "2007-07-04T10:45:33Z")

</div>

Hi,

I have a SystemStackError. Here is the stack (sorry if it’s a little  
long) :

app/models/line\_item.rb:14:in `product’

app/models/line\_item.rb:14:in `product’

app/controllers/store\_controller.rb:188:in `redirect\_to\_paypal’

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/association\_proxy

.rb:123:in `each’

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/association\_proxy

.rb:123:in `send’

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/association\_proxy

.rb:123:in `method\_missing’

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/has\_many\_association

.rb:98:in `method\_missing’

app/controllers/store\_controller.rb:187:in `redirect\_to\_paypal’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:1095:in `send’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:1095:in `perform\_a

ction\_without\_filters’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:632:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:638:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:438:in `call’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:637:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:638:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:438:in `call’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:637:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:638:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:438:in `call’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:637:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:638:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:438:in `call’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:637:in `call\_fi

lter’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:619:in `perform

\_action\_without\_benchmark’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/benchmarking.rb:66:in `per

form\_action\_without\_rescue’

/opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/benchmarking.rb:66:in `per

form\_action\_without\_rescue’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/rescue.rb:83:in `perform\_a

ction’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:430:in `send’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:430:in `process\_wi

thout\_filters’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:624:in `process

\_without\_session\_management\_support’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/session\_management.rb:114:in

`process’

/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:330:in `process’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in  
`dispatch’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:  
113:in `handle\_dispatch’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:  
79:in `service’

/opt/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’

/opt/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’

/opt/local/lib/ruby/1.8/webrick/server.rb:173:in `start\_thread’

/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start’

/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start\_thread’

/opt/local/lib/ruby/1.8/webrick/server.rb:95:in `start’

/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `each’

/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `start’

/opt/local/lib/ruby/1.8/webrick/server.rb:23:in `start’

/opt/local/lib/ruby/1.8/webrick/server.rb:82:in `start’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:  
63:in `dispatch’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/  
webrick.rb:59

/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem\_original\_require’

/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require’

/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/  
active\_support/dependencies.rb:495:in `req

uire’

/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/  
active\_support/dependencies.rb:342:in `new

\_constants\_in’

/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/  
active\_support/dependencies.rb:495:in `req

uire’

/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:  
39

/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem\_original\_require’

/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require’

script/server:3

This is the method that is being called :

def redirect\_to\_paypal  
create\_order  
more\_options = Hash.new

```
x = 1
@order.line_items.each do |item|
  more_options["item_name_#{x}"] = item.product.title # this is

```

the line that is causing the error  
more\_options[“amount\_#{x}”] = item.product.price  
more\_options[“quantity\_#{x}”] = item.quantity  
x += 1  
end

```
@html = render_to_string( :partial => "switch_to_paypal", :object

```

=\> @order, :locals =\> { :more\_options =\> more\_options } )  
end

Can someone figure out what is causing this error ?

Thanks, Marc

---

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/2 "2007-07-04T12:27:39Z")

</div>

> ```
> @html = render_to_string( :partial => "switch_to_paypal", :object
> 
> ```
> 
> =\> @order, :locals =\> { :more\_options =\> more\_options } )  
> end

i think it has to do with scope issues:

when you call :more\_options to pass as a parameter, you’re creating a  
local variable, and passing it the local variable that already exists  
(but since it is the same variable-name, you are passing it the one you  
are creating, which is the one that already exists, which is … a stack  
way too deep.)

i think.  
if you change the variable name you’ve created in the loop to something  
else, does it work?

i.e

```
@order.line_items.each do |item|
  more_options_hsh["item_name_#{x}"] = item.product.title # this is

```

the line that is causing the error  
more\_options\_hsh[“amount\_#{x}”] = item.product.price  
more\_options\_hsh[“quantity\_#{x}”] = item.quantity

and then

…  
…=\> @order, :locals =\> { :more\_options =\> more\_options\_hsh } )

?

---

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 2:18pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/3 "2007-07-04T14:18:00Z")

</div>

Hi Shai,

Thanks for your advice. Unfortunately, I get the same error after  
having renamed my variable.  
I’ve googled the net and haven’t yet found a solution.

anyone ?

---

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/4 "2007-07-04T17:21:26Z")

</div>

CPerry, thank you a thousand times ! I had in a LineItem model file a  
function :

def product  
self.product  
end

this was causing the recursion ( I don’t know why I had written this  
function in the first place).

Marc

---

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/5 "2007-07-04T14:48:02Z")

</div>

I had this same problem yesterday, and it was because I was calling a  
variable twice and it was simply looping itself over and over.  
Renaming the variable worked for me. It was posting to a column in my  
DB, then trying to post a value to the same column, so it just  
continuously looped itself.

Sorry I can’t be more help! Just check to be sure that you are not  
calling a variable and then calling it again somewhere else with  
different values.

–Cory

---

<div class="post-metadata">

**Author:** ![mpalluat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@mpalluat](https://www.ruby-forum.com/u/mpalluat)\
**Post date:** [July 4, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/stack-level-too-deep/108515/6 "2007-07-04T19:27:38Z")

</div>

Awesome, glad you found the error.

–Cory
