ruby-on-rails – Rails link_to方法:: delete

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails link_to方法:: delete前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很抱歉问什么可能是一个补救问题,但在学习rails时我试图按照本教程中的注释说明:

http://guides.rubyonrails.org/getting_started.html

我昨晚在本教程中发布了一个类似的问题并得到了一个迅速响应,这对我帮助很大,所以我希望同样如此.先感谢您.

第5.14节:删除帖子

我被指示向index.html.erb页面添加删除链接

  1. <h1>Listing Posts</h1>
  2. <table>
  3. <tr>
  4. <th>Title</th>
  5. <th>Text</th>
  6. <th></th>
  7. <th></th>
  8. <th></th>
  9. </tr>
  10.  
  11. <% @posts.each do |post| %>
  12. <tr>
  13. <td><%= post.title %></td>
  14. <td><%= post.text %></td>
  15. <td><%= link_to 'Show',post_path %></td>
  16. <td><%= link_to 'Edit',edit_post_path(post) %></td>
  17. <td><%= link_to 'Destroy',post_path(post),method: :delete,data: { confirm: 'Are you sure?' } %></td>
  18. </tr>
  19. <% end %>
  20. </table>

产生:

  1. <td><a data-confirm="Are you sure?" data-method="delete" href="/posts/1" rel="nofollow">Destroy</a></td>

对我来说看起来不错,但是当我点击链接时,我既没有得到确认,也没有指向删除操作.它会生成此HTTP操作

  1. Request URL:http://localhost:3000/posts/1
  2. Request Method:GET
  3. Status Code:200 OK

Rails:4,Ruby:2,64位windows 8,chrome:版本28.0.1500.72 m

再次感谢你

添加application.html.erb

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Listing</title>
  5. <%= stylesheet_link_tag "application",media: "all","data-turbolinks-track" => true %>
  6. <%= javascript_include_tag :application %>
  7. <%= csrf_Meta_tags %>
  8. </head>
  9. <body>
  10.  
  11. <%= yield %>
  12.  
  13. </body>
  14. </html>

产生了这个错误

ExecJS::RuntimeError in Posts#index Showing
C:/Ruby-Projects/listing/app/views/layouts/application.html.erb where
line #6 raised:

(in
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.3.0/lib/assets/javascripts/turbolinks.js.coffee) Extracted source (around line #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

Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in
`_app_views_layouts_application_html_erb___567964991_28724900′ Request

Parameters:

None

的application.js

  1. //= require jquery
  2. //= require jquery_ujs
  3. //= require turbolinks
  4. //= require_tree .

解决方法

确保你有
  1. //= require jquery
  2. //= require jquery_ujs

到application.js文件和application.js文件包含在view / layout / application.html.erbfile中

猜你在找的Ruby相关文章