我无法使用destroy方法来工作。当我点击删除时,没有任何反应。没有确认弹出,帖子没有被删除。 控制器中的方法:
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path, :notice => "Your post has been deleted successfully."
end
观点:
<%= link_to "Delete post", @post, data: { confirm: "Are you sure?" }, :method => :delete %>
呈现HTML:
<a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/posts/8">Delete post</a>
application.html.erb文件就像创建它一样:
<!DOCTYPE html>
<html>
<head>
<title>Myrubyblog</title>
<%= stylesheet_link_tag 'application', media: 'all', 'dataturbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<% flash.each do |key, value| %>
<p><%= value %></p>
<% end %>
<%= yield %>
</body>
</html>
&#13;
编辑,其他一切正常。任何使这项工作的想法?谢谢
解决了! 问题出在application.html.erb文件,javascript_include_tag中。当我开始这个项目时,我在Pages#home&#39;中得到了Rails ExecJS :: ProgramError,所以我更改了javascript_include_tag&#39; application&#39;进入&#39;默认&#39; (正如人们在这个帖子中所说的stackoverflow.com/questions/28421547 / ...)。现在我将其更新为&#39; application&#39;它按预期工作。谢谢,凯文!
答案 0 :(得分:1)
试试这个
<%= link_to 'Delete post', @post, method: :delete, data: { confirm: 'Are you sure?' } %>