Ich sehe viele Leute, die über dasselbe Problem berichten, aber keine der Antworten hat für mich bisher funktioniert. Hier ist, was ich habe:Devise Abmelden Link wird nicht zu DELETE posten, nur GET, was nicht funktioniert
In application.html.erb
:
<%= link_to 'Logout', destroy_user_session_path, :method => :delete %>
, das die folgenden HTML erzeugt:
<a rel="nofollow" data-method="delete" href="https://stackoverflow.com/users/sign_out" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Logout</a>
Leider ist diese Verknüpfung zu Benutzer # zeigen statt der Entsendung als DELETE an Benutzer/Sessions # Zerstöre so, wie es soll.
Mein config/routes.rb
hat:
devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }
resources :users, only: [:show, :edit, :update]
Und rake routes
kehrt:
new_user_session GET /users/sign_in(.:format) users/sessions#new
user_session POST /users/sign_in(.:format) users/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
So ist die link_to
destroy_user_session_path
mit :method => :delete
funktionieren sollte.
Mein application.js
hat:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require turbolinks
//= require skel.min
//= require_tree .
Ich habe auch die folgenden in der <head>
von application.html.erb
:
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
Das sind die vorgeschlagenen Lösungen, die ich je gesehen habe, aber keiner von ihnen arbeiten. Die einzige andere Lösung, die ich gesehen habe, ermöglicht eine GET
Methode, sich abzumelden, aber ich würde es gerne RESTful wenn möglich zu halten.
Irgendwelche Ideen?
Versuch 'Ressourcen: Benutzer' - setzt nicht die einzigen Bedingungen, nachdem es – gwalshington
kein Glück, nimmt mich immer noch: GET „/ users/sign_out“ ... Verarbeitung von Userscontroller # show als HTML – jfredson