Stack level too deep error in Ruby on Rails
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.
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 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
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.