我有以下用于洗掉草稿帖子的腳本
<%= link_to "Delete", api_post_path(draft), method: :delete,
remote: true %>
它可以正常作業,但是在將 rails 版本更新到7.0.3它之后就不再作業了。
這些是我的專案資訊
- 我有圖書館收藏
# app/controllers/libraries_controller.rb
class LibrariesController < ApplicationController
...
def drafts
@drafts = current_user.posts.recent.drafts.paginate(page: params[:page])
end
...
end
- 我有這個用于洗掉草稿帖子的集合
# app/controllers/api/posts_controller.rb
module Api
class PostsController < ApplicationController
...
destroy
@post = current_user.posts.friendly.find(params[:id])
@post.destroy
end
...
end
end
- 這是我的路線
# config/routes.rb
namespace :api do
resources :posts, only: [:create, :update, :destroy]
end
- 查看以顯示所有草稿帖子串列以及洗掉草稿帖子的鏈接
<!-- app/views/libraries/drafts.html.erb -->
<div id="library_<%= draft.id %>">
...
<%= link_to "Delete", api_post_path(draft), method: :delete,
remote: true %>
...
</div>
<!-- app/views/api/posts/destroy.js.erb -->
$('#library_<%= @post.id %>').fadeOut();
但現在它不起作用然后我洗掉method: :delete并更新了新腳本
<%= link_to "Delete", api_post_path(draft), data: {
turbo_method: "delete",
turbo_confirm: "Are you sure?"
},
remote: true %>
它仍然無法正常作業,然后我通過洗掉再次更新了腳本remote: true
<%= link_to "Delete", api_post_path(draft), data: {
turbo_method: "delete",
turbo_confirm: "Are you sure?"
} %>
之后,我得到了這個錯誤
No route matches [GET] "/api/posts/xxx"
請告知我該如何解決這個問題
uj5u.com熱心網友回復:
使用以下
<%= link_to "Delete", api_post_path(draft), method: :delete, data: { turbo: false } %>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/482367.html
上一篇:Wordpress6script-loader.php問題
下一篇:為應用程式(ruby2.3.8,rails4.2.11)尋找推薦的升級路徑到ruby??和rails的最新穩定版本
