我正在学习博客教程。按照指示,我在\views\articles\index.html.erb中有以下代码:
<h1>Listing Articles</h1>
<%= link_to 'New article', new_article_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>我在\controllers\articles_controllers.erb中有这样的代码:
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end然而,当我尝试删除时,我得不到任何“你确定吗?”对话框,则无法删除该记录。
我遗漏了什么?
发布于 2016-02-20 22:29:18
确保您的代码中包含以下内容:
Gemfile
gem "jquery-rails"app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs发布于 2016-02-20 22:42:19
我想缺少的一点是,
您将使用以下内容完成展示路径
article_path(article)只要销毁路径是通过post请求处理的,并且在第二个实例中成为我们所知道的销毁路径,您就应该这样做
<td><%= link_to 'Destroy', article,
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>发布于 2016-02-20 22:44:06
您是否在浏览器中禁用了JavaScript ?如果是,请将其打开
https://stackoverflow.com/questions/35524340
复制相似问题