http://guides.rubyonrails.org/getting_started.html
昨晚我在这个教程中发布了类似的问题,并得到了及时的回复,这对我有很大帮助,所以我希望得到同样的帮助。提前感谢你。
第 5.14 节:删除文章
我被指示在 index.html.erb 页面上添加删除链接。
<h1>Listing Posts</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.text %></td>
<td><%= link_to 'Show', post_path %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post_path(post),
method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
生成:
<td><a data-confirm="Are you sure?" data-method="delete" href="/posts/1" rel="nofollow">Destroy</a></td>
我认为它看起来还不错,但是当我点击链接时,既没有得到确认也没有被引导到删除操作。它生成了这个HTTP动作。
Request URL:http://localhost:3000/posts/1
Request Method:GET
Status Code:200 OK
使用的技术栈为:Rails 4、Ruby 2,操作系统为64位Windows 8,浏览器版本为Chrome Version 28.0.1500.72 m。
再次感谢您!
添加application.html.erb文件
<!DOCTYPE html>
<html>
<head>
<title>Listing</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag :application %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
这导致了以下错误:
Posts#index中的ExecJS::RuntimeError,显示在C:/Ruby-Projects/listing/app/views/layouts/application.html.erb,其中 第6行引发了错误:
(在 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.3.0/lib/assets/javascripts/turbolinks.js.coffee) 摘录(大约6行附近):3 4 5 6 7 8 9 Listing <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag :application %> <%= csrf_meta_tags %>
Rails.root: C:/Ruby-Projects/listing
应用跟踪 | 框架跟踪 | 完整跟踪 app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___567964991_28724900' 请求
参数:
无
application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
<%= javascript_include_tag :applicaton %>
? - Marek LipkaJavaScript
代码正确无误。 - Marek Lipka