通过js处理删除响应,我将通过turbolinks重新加载curent页面。换言之:
// onclick setup encapsulates the following
axios({
method: "delete",
url: e.target.getAttribute("href"),
headers: Csrf() // passes the csrf token to keep things 'rails'
}).then(() => {
Turbolinks.visit(locationWithoutHash, { action: "replace" });
});我们的登录链接就是这样处理的。
签出,然后重定向到root_url。
问题是,Turbolinks.visit似乎保留了最初的方法:
Started DELETE "/auth/sign_out" for 127.0.0.1 at 2018-04-22 11:21:12 +0200
Processing by Devise::SessionsController#destroy as HTML
...stuff
Redirected to http://demodemo.lvh.me:3000/
Completed 302 Found in 11ms (ActiveRecord: 1.9ms)
Started DELETE "/" for 127.0.0.1 at 2018-04-22 11:21:12 +0200
ActionController::RoutingError (No route matches [DELETE] "/"): etc...这可能只是语法/语法的问题,我在源代码中找不到。
如果不讨论这种行为是否有意义,那么是否有可能为Turbolinks.visit指定一个方法,以确保它有效地通过GET?(因为我只是使用它来重新加载当前页面,无论发生什么情况,它总是一个GET)
发布于 2018-04-23 04:47:16
当destroy方法在删除redirect_to request.referer或任何类似的URL之后是这样发生的,如果您有这样的情况,那么就改为像这样
def destroy
@obj = Model.find(params[:id])
respond_to do |format|
if @obj.destroy
flash[:error] = 'Deleted'
format.html { redirect_to request.referer, status: 303 }
format.js { redirect_to request.referer, status: 303 }
end
end
end我想这会有帮助的
https://stackoverflow.com/questions/49964468
复制相似问题