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
Undefined method users_url in SessionController #1350
Comments
Could you please provide a failing test case to Devise code base? That would help us a lot to understand and fix the issue. |
I'm actually a relatively new Rails developer and I haven't yet gotten so far as to develop test cases for my project. I'm sure that doesn't help...is there anything else I could provide to help locate the source of the problem? |
Can you provide a sample application that reproduces this error and push it to Github and show us the rest tester that you are using? btw, have you added :json to navigational formats in your devise initializer? |
Okay, I was in the process of creating a sample application to show the bug, but when I checked the routing, I noticed that in my sample application the Devise installation left "resources :users" in after the devise_for line. I put that line back in my original project, and JSON sign_in worked properly. So the moral of the story is that the resources line in the routes file must be left in (just in case any other Rails developers come across this issue). Thanks so much for your quick responses, this is a great project! |
@josevalim just ran into this myself today. I'm not sure why the Just to clarify our routes look like this: devise_for :users,
controllers: {
registrations: "users/registrations",
confirmations: "users/confirmations",
sessions: "users/sessions",
passwords: "users/passwords",
}, :path_names => {:sign_in => "login", :sign_out => "logout"} It works fine for regular form logins and it even works for JSON as long as the login is successful. But if I submit an empty form or a bad username or password I get the undefined method 'user_url' error mentioned above. As @mathcolo mentioned, it does work when I added |
@LucisFerre we still need a way to reproduce the issue. otherwise there is nothing we can do. :S |
I do not know if it's the same issue, but I adding resources :users helped my code as well to make my rspec tests pass. Here's my situation: upgrading from 1.5.3 to 2.1.2, with a User model, and the following custom code:
And corresponding controllers that override a few things from Devise. In my controllers, as part of the upgrade, I tried to copy anything new that made sense. For instance:
Previously, I did not have |
I created a github project that causes
Perhaps there's a bug in my code, but it's really pretty simple. Here's the repository of a very simple Rails app with an rspec test that causes things to blow up: https://github.com/davidw/devise-rspec-registration-create-bug |
I pushed another update to my mini project that does a STDERR.puts resource.errors, and it shows that it has no 'messages', even though it's clearly not an ok user. |
More data: I tried adding this to the user.rb file in my example project:
It does not get called in the tests, but gets called when accessing things 'normally', in a browser. Something else that's strange, is, if in the create method in RegistrationsController, I call save! instead of save, it errors out correctly. |
If, in Devise::RegistrationsController#build_resource, I call |
Argh... never mind, I'm a moron. This is what's causing the problem.
It used to work and now it does not, for whatever reason, but it's clearly what's causing things to go haywire. Argh! anyway, I think this can be closed. |
I have the same issue and no solution. Can this issue be re-opened? |
I had the same error when overriding RegistrationsController, but it works when i add error to resource before respond
this |
I have the same original issue, without "resources :users", I get a "undefined local variable or method `users_path'" error. |
@Tuman829 if you're still having this issue, please open a new issue with your rails version, devise version, a stacktrace, and, if you're feeling motivated, a failing example app or test case. It's possible we won't be able to help you unless you provide one of the last two items but we try to reserve the Github issues for bugs with devise and direct everyone to the mailing list for support. Also keep in mind that if your devise version matches the original issue here, our first advice will be to upgrade to a more recent version as we don't generally push fixes to older releases unless they are security critical. |
I am running the newest version of devise, let me see what I can do. I have posted in the mailing list as well. |
If there is some sort of error in the code, this error could be thrown. In my case, I was trying to redirect to previous url after signin and it looks like I had an extra end in my application controller code. I was commenting out my code one by one and retracted back. Now I don't have this error nor I am able to redirect to previous url. Still trying... Thanks for all the inputs. |
I had this error, but only when I was trying to deep link in to my app when not logged in. It turned out to be a sneaky little bug, one that's worth remembering. I had overridden
However, when you call I now have
|
This is happening because your implementation of |
It's June 2016 and the error still occurs. |
@doncadavona - This should be working fine. Are you redefining after_sign_in_path_for? What does 'grep -r after_sign_in_path_for app/' return? |
@mib32 was my solution. |
My solution was to remove |
for me, the solution was to set this config option to # config/initializers/devise.rb
# If 401 status code should be returned for AJAX requests. True by default.
config.http_authenticatable_on_xhr = true |
I'm using the master branch of Devise in my project and when I use a REST tester to POST to /users/sign_in.json, I get a NoMethodError:
Here is the full trace:
How do I/we remedy this bug? Thanks!
The text was updated successfully, but these errors were encountered: