在禁用“涡轮”之后,我的删除方法无法正常工作。在铁轨7中?

发布于 2025-02-10 22:13:45 字数 578 浏览 2 评论 0原文

我正在使用Rails 7。在禁用“ Turbo”后,我正在尝试运行“删除”方法 不起作用,它不断进入我的'show.html.erb'文件,而不是删除特定数据。这是我的“删除”操作代码:

<td>

    <%= link_to 'Delete', friend_path(friend),  data: { turbo:false ,confirm: 'Are you sure?'}, method: :delete, :class=>"btn btn-danger"%>

  </td>

下面是销毁/删除数据的控制器方法

def destroy 
debugger
@friend = Friend.find(params[:id])
@friend.destroy

if @friend.destroy
    redirect_to friends_path, notice: "Deleted Successfully!!!"
else
  render :index, status: :unprocessable_entity

结束

I am working on rails 7. I'm trying to run my 'Delete' method after disabling 'Turbo' but its
not working, it keeps getting to my 'show.html.erb' file instead of deleting the specific data. Here is my 'Delete' action code:

<td>

    <%= link_to 'Delete', friend_path(friend),  data: { turbo:false ,confirm: 'Are you sure?'}, method: :delete, :class=>"btn btn-danger"%>

  </td>

And below is the controller method to destroy/delete data:

def destroy 
debugger
@friend = Friend.find(params[:id])
@friend.destroy

if @friend.destroy
    redirect_to friends_path, notice: "Deleted Successfully!!!"
else
  render :index, status: :unprocessable_entity

end

end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2025-02-17 22:13:45

删除不起作用,是因为您在禁用“涡轮增压”后没有加载jQuery。

将jQuery添加到您的布局或页面上

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

,应该重新开始工作

Delete is not working is because you are not loading jQuery after disabling 'Turbo'.

Add jquery to your layout or page

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

and it should start working again

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文