New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Including url_helpers in class causes error #3144
Comments
I tried to create a test in rails that caused this problem. I could not. I figured it could be fixed in edge, or I could be mocking things out incorrectly. I ended up creating a new Rails 3.1.0 app and tried to reproduce the issue. It looks like it isn't a problem. https://github.com/kenmazaika/test_app/blob/master/test/unit/simple_class_test.rb That test passes fine on my machine with rails 3.1.0. Is there a chance you're doing something like: def hello_url ?? Can you reproduce this issue in a test repo like this? |
I think it might be because of some other things loaded in the Rails environment? Try this in console: Loading production environment (Rails 3.1.0) |
I don't think this is a bug in IRB. Will you modify my test project to reproduce the error or post our routes.rb and user.rb files? |
Sorry - that was part of the output I copy/pasted - I'm not saying it was bug in IRB. Just showing you how to reproduce the exception. include those two modules and call polymorphic_path. |
In response to your question: I think it might be because of some other things loaded in the Rails environment? Yes. I think it's caused by the user.rb file that is loaded in your environment. I think there is a bug in that code or it's doing something that it isn't allowed to that is not documented. |
In this case I called user.rb - the same thing happens no matter what model I load. |
I am experiencing the exact same problem. While I try to track it down, I wanted to post my Gemfile: https://gist.github.com/1294166 . Perhaps if others do the same we can target an offending external library quicker. |
I'm having a similar issue too. No idea how to get rid of it. Often times, it will only happen on the 2nd request I do (while in development mode). |
I have alleviated the problem in my app, but am not sure specifically what was causing it. I do not think that url_helpers are the root problem, just another symptom. I put some debugging code in the reloader middleware and saw that it was the controller callbacks that were causing these errors to occur (possibly a circular loop in the callback stack?). The callbacks code uses a lot of meta-programming and debugging of the root problem fell down there. That being said, the controller that was causing this error was inheriting from two other controllers between it and the ApplicationController. These parent controllers are used to share *_filters and associated private methods. Imagine:
While this seemed like a good idea at the time, I think that using modules is a better approach. So, I changed it to:
Where The RealRoutedController had modules included to capture shared logic. This alleviated the problem entirely for me. YMMV, but if you are doing anything past vanilla filters you may want to explore was to refactor them. |
I have a similar issue, but whenever I have a scope in a model.. |
Another piece of the puzzle. My controller is just a scaffold, as Rails generated it. My model is entirely hand-crafted though, wrapping ActiveModel. I read this:
which reminded me that my model looked like this (and rspec was green):
(In my defense, I knew it was a hack when I wrote it, but the specs didn't pass beforehand, so I assumed I took the overriden Alas, dropping the offending code into a fresh Rails app did not reproduce the issue, but hopefully this extra info will be helpful in tracking down the real problem. |
Had the same issue, but updating gems with "bundle update" fixed it... |
I had this problem, too. Got around it by calling the helpers directly from my model, like so: Rails.application.routes.url_helpers.users_url The problem still exists, though... |
Closing this as I can't reproduce it - the stack level too deep message is usually an indication of recursion, so something like a method name collision is probably the cause. If someone can either do a simple steps to repeat or create a repo that reproduces the error I'll reopen it and take a look. |
Like @elsurudo I had this problem (in a model) and traced it to the Just a datapoint, I do not yet have a reproduction to share for reopening. |
@gerwitz use backticks instead of underscores when referencing code, I got real confused reading your comment. ;) I've edited it. |
Whoah, sorry for thread necromancy. I opened all my github emails from my email, no idea why it linked here. |
I was having this problem, when migrating from 3.0 to 3.1, when running any rake task. To reproduce, follow the steps
You may run into the same problem with Rails 3.2.x More details here: http://stackoverflow.com/questions/14739515/stack-level-too-deep-error-when-running-any-rake-task Can this issue be reopened? |
I just faced this issue in 3.2.14, so it's there. |
I also get this when I try to use the url_helpers in minitest:
|
Sorry guys, I'm reopening this since @shadowmaru gave a way to reproduce this and following the steps, I got the "stack level too deep" error (on master and 4.0.1 apps). |
What's the use case for including |
I am able to reproduce this issue. If you include |
@sandipransing can you post the code that reproduces it? |
Create some rake file and add
Now if you try to run
|
@carlosantoniodasilva |
I see.. now, why would you include the helper in the top level? And also, which version are you testing against. |
@carlosantoniodasilva i am testing against edge rails. |
The question remains. why would you include the helper in the top level? |
@carlosantoniodasilva @rafaelfranca My case was that I had to include another helper ( The issue (stack level too deep) is specific to |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
This issue has been automatically closed because of inactivity. If you can still reproduce this error on the Thank you for all your contributions. |
I'm including url_helpers in a class and am getting the following error:
My include is as follows:
This worked in rails 3.0. I've also tried including the UrlFor module. The class is a PORO in app/models.
The text was updated successfully, but these errors were encountered: