I\'m having a stack level too deep error using Ruby 1.8.7 with Rails 3.0.4 and with the rails console I performed the following commands.
The stack level too deep error occurs also, if you want to destroy a record and you have an association with :dependent => :destroy
to another model. If the other model has a association with :dependent => :destroy
back to this model, the stack level is too deep, too.
If you are getting this error it means rails version that you are using in your application is not compatible with Ruby Version.
Solutions you can use to solve this issue.
1) You need to downgrade the ruby version to older version.
2) or you need to upgrade Rails to latest version.
This error generally happens when you accidentally recursively changing an attribute. If you have a username attribute in User model, and a virtual attribute named username, that is directly changing the username, you end up calling the virtual, the virtual calls the virtual again and so on.. Therefore, take a look on whether something like that happens somewhere in your code.
I had a "stack-level too deep"
issue too. it was due to recursiveness in one of my functions and had been caused by a typo as you can see from below:
def has_password?(submitted_password)
encrypt_password == encrypt(submitted_password)
end
private
def encrypt_password
self.salt = make_salt unless has_password?(password)
self.encrypted_password = encrypt(password)
end
I realised I had to change the second line to encrypted and it worked. Just checkout for recursion in your code it must be happening somewhere. Unfortunately I can't be of better use since I can't look at all your code files.
As you are not showing all the code, I can only speculate that you have defined inspect
or to_s
to build a string containing, among other things the parents.
Your current parents
method doesn't seem to be doing anything reasonable, as it returns all organisations that are companies, no matter which association you start from. Thus, any company has itself as parent. Attempting to convert it to string will induce an infinite loop to try to show the parents' of the parents' of ...
In any case, the bulk of your parents
method should be in a helper, called something like options_for_parents_select
, because that's what it seems to be doing? Even then, the first empty choice should be passed as allow_null
to select.
The fact that it sets instance variables is a code smell.
Good luck
I was getting same stack level too deep error & it turns out that the issue was of recurring rendering of a partial.
I happened to call render a_partial in main view and then in the partial, I accidentally called the same partial again.
HTH