-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Devise 4.8.1 + Rails 7.0.0 | Undefined method 'user_url' #5439
Comments
Ran into this at the same time as you 😆 Quick fix, tl;drAdd config.navigational_formats = ['*/*', :html, :turbo_stream] More detailA few lines from a trace starting with the offending line in registrations controller:
devise/app/controllers/devise/registrations_controller.rb Lines 111 to 113 in 025b1c8
devise/lib/devise/controllers/helpers.rb Lines 264 to 266 in 025b1c8
Lines 218 to 220 in 025b1c8
Basically, requests in Rails 7 may come with format I'm happy to open a PR for this, though someone with more familiarity with turbo should sanity check it. |
Fixes heartcombo#5439 Rails 7 returns :turbo_stream as a request format out-of-the-box.
@erik-brueggemann my understanding is that method: :delete won't work with a link_to when not using UJS (which is not a dependency by default in Rails 7). So the sign_out method is going to be called as a GET, which is the fallback, resulting in an error. You can try changing link_to to button_to (which I don't like), or add data-turbo-method="delete", like so:
A problem I am trying to find a solution for with this approach is that upon singing out it won't redirect to the root, but to the page the user was on before signing out, which, of course, most probably requires authorisation, so it is not the best experience. The approach above works without the @nickrivadeneira fix (however, you might be experiencing a different issue). I'm not sure what is it changes exactly in the behaviour. I was hoping it will be a fix for my issue, but it isn't... any help will be appreciated. |
Hi @nortonandreev, the problem you're describing is yet another one that resulted from the Rails 7 / turbo-rails aftermath as far as I can tell. This particular issue here wasn't meant to address the log out mechanism, but rather user registration only. For that, the fix suggested by @nickrivadeneira makes sense to me - nevertheless you've got a point! It's probably a good idea to open a separate issue to find a permanent solution for that? But since we've already brought it up, instead of changing from # The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :get # <= change this from :delete to :get and remove the `method:` in your `link_to` helper Happy to open up another issue if ya'll think it's two separate topics. |
just curious - wouldn't that open one up to csrf attacks? |
The changelog says that "Please note that Turbo integration is not fully supported by Devise yet.". It would be nice if someone familiar with the matter updates us on what does this mean exactly and if there is some ETA of when full support will be added. I don't really want to waste hours implementing hacky solutions which might make my app vulnerable. On the other hand, I don't want to be waiting forever, if devise won't be fully updated to support Rails 7. |
method: :delete in my link_to dont working, only work this format > |
For now you have to disable turbo on devise links, i.e. |
all right, thanks. |
As noted by @nortonandreev this worked for me in an app with Rails 7 and importmap <%= link_to "Log out", destroy_user_session_path,
data: {
"turbo-method": :delete
} %> |
This solved my issue to help me close out the initial setup of my new application that I'm working on, thank you! |
The suggestion by @nortonandreev works for me, but adds an additional, failing and unnecessary (DELETE) HTTP request:
|
I added |
I am on Rails 7.0.2.3 and I didn't have this issue. Maybe upgrading to this version of rails or higher might fix it, |
im having this same problem in a app with bootstrap, link_to perfoms GET method instead DELETE even if i use data: {turbo_method: :delete} |
@omokehinde dont work im using the rails 7.0.2.3 and i have the same issue but when i register a user |
It works for me |
My app worked fine until suddenly I got these errors: NoMethodError (undefined method 'user_url' for #<Devise::RegistrationsController:0x0000000000d638>) Thanks to @nickrivadeneira for posting a fix here heartcombo/devise#5439 (comment)
This is a step from github issue 5439 It get error. Receiving NoMethodError (undefined method 'user_url' for #<Devise::RegistrationsController:0x0000000000d638>) upon successful user registration. User gets persisted in database heartcombo/devise#5439
Add turbo_stream as navigational format in order to fix redirect after user registration. heartcombo/devise#5439 (comment)
Hi everyone, This is what I did
I am attaching the repository |
This solution worked for me too! |
My sample app is working fine with the changes I described here: I tested these behaviors:
|
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Wanted to confirm that the article that @JunichiIto posted/wrote worked successfully for me. Thank you! |
The main branch should contain all that's necessary for fully working with Turbo now, which should fix this. A new version will be released soon, but feel free to test it out from the main branch in the meantime, and report back on any issues. Thanks. |
I have same issue after installing |
@alex223125 I don't know much about that gem to help, sorry. They may need some tweak to work with Rails 7 and / or this latest Devise version. |
What about the case where the object is not persisted? I'm getting the same error on this line
|
@botsarenthuman my first wild guess is that you're hitting something like this: #5565 (comment), where the object does not contain any errors associated with it (even if it's not persisted), so responders will try to redirect (it uses the presence of errors to determine how to respond), causing the error. |
… the invitations limit.. I added data: { turbo: false } following the suggestion https://github.com/heartcombo/devise/issues/5439\#issuecomment-1021131680
Pre-check
rails new app-name -a propshaft -j importmap -c tailwind
gem 'devise', '~> 4.8', '>= 4.8.1'
toGemfile
and followed installation instructionsEnvironment
Current behavior
NoMethodError (undefined method 'user_url' for #<Devise::RegistrationsController:0x0000000000d638>)
upon successful user registration.Demo app to reproduce the error is available here
Expected behavior
root_path
without errorThe text was updated successfully, but these errors were encountered: