当我尝试退出时,我收到错误的无路线匹配[GET]" / users / sign_out"。 这是我的Signout链接标记。
<%= link_to "Sign Out", destroy_user_session_path, method: :get , class: "nav-link" %>
以下是与我的用户模型和Devise相关的路线:
Rails.application.routes.draw do
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
root 'books#index'
resources :books do
member do
put "like", to: "books#upvote"
end
end
end
这是我的devise.rb
config.sign_out_via = :get
答案 0 :(得分:7)
在 routes.rb
中尝试以下操作devise_for :users
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'
end
了解更多信息how to by devise
答案 1 :(得分:1)
如果您打算保留注销/users/sign_out
的默认路径路径,请执行以下操作:
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
应该采用的方式之一是:
使用DELETE方法代替GET
<%= link_to "Sign Out", destroy_user_session_path, method: :delete, class: "nav-link" %>
-OR -
编辑devise.rb初始化程序并更改
config.sign_out_via = :delete
至config.sign_out_via = :get
答案 2 :(得分:1)
确保这一点:
你的Gemfile中的包括
import Ember from 'ember';
var sortByAuthor = function(a,b) {
if (a.author > b.author) {
console.log(a + " is greater than " + b);
return 1;
}
else {
console.log(b + " is greater than " + a);
return -1;
}
};
var sortByTitle = function(a,b) {
if (a.title > b.title) {
console.log(a + " is greater than " + b);
return 1;
}
else {
console.log(b + " is greater than " + a);
return -1;
}
};
export default Ember.Controller.extend({
actions: {
sortAuthors() {
var myModel = this.get('model');
console.log(myModel[0].author);
myModel.sort(sortByAuthor);
console.log(myModel[0].author);
this.set('model', myModel);
},
sortTitles() {
var myModel = this.get('model');
myModel.sort(sortByTitle);
console.log(myModel[0].title);
this.set('model', myModel);
}
}
});
在application.js
中gem 'jquery-rails'
在我看来,改变路由器或签出的方法并不是那么好,这个动作应该总是用DELETE来完成。这对我有用。
答案 3 :(得分:0)
由于您要销毁会话,因此它不是:get
方法,而是:delete
。将链接修改为:
= link_to "Log out", destroy_user_session_path, method: :delete
答案 4 :(得分:0)