Rails link_to方法:: delete [英] Rails link_to method: :delete

查看:114
本文介绍了Rails link_to方法:: delete的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉询问可能是一个补救问题,但是在学习rails时,我试图按照本教程中的说明进行操作:

I am sorry for asking what may be a remedial question, but in learning rails i was trying to follow along note for note in this tutorial:

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

I昨晚在本教程中发布了一个类似的问题并得到了一个明显的帮助,这对我有很大的帮助,所以我希望也能如此。提前谢谢。

I posted a similar question from this tutorial last night and got a prompt response which helped me significantly, so I am hoping for the same. Thank you in advance.

第5.14节:删除帖子

Section 5.14: Deleting Posts

我被指示添加删除链接到index.html.erb page

I am instructed to add a delete link to the index.html.erb page

<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操作

It looks OK to me, but when I click on the link I get neither the confirmation nor am I directed to the delete action. It generates this HTTP action

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

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

Rails: 4, Ruby: 2, 64 bit windows 8, chrome: Version 28.0.1500.72 m

再次感谢

添加application.html.erb

Adding the 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>

产生了这个错误:


帖子中的ExecJS :: RuntimeError #index显示
C:/Ruby-Projects/listing/app/views/layouts/application.html.erb其中
第6行引发:

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


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

列出
<%= stylesheet_link_tagapplication,媒体:全部 ,data-turbolinks-track=> true%>
<%= javascript_include_tag:application%>
<%= csrf_meta_tags%>

(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

Rails.root: C:/Ruby-Projects/listing

应用程序跟踪|框架跟踪|完整跟踪
app / views / layouts / application.html.erb:6:in
`_app_views_layouts_application_html_erb___567964991_28724900'Request

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

参数:






application.js


application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .


推荐答案

好的我需要从应用程序中删除这两行。 js

OK i needed to remove these two lines from application.js

//= require turbolinks
//= require_tree .

摆脱了ExecJS运行时错误。为什么默认包括这些,我应该首先弄清楚它们为什么会导致错误?

which got rid of the ExecJS run time error. Why were these included by default, and should I be figuring out why they were causing an error in the first place?

FWIW - 删除功能现在可以使用。

FWIW - the delete functionality now works.

这篇文章的道具:

https://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-7-trying-to -follow-rubytutorial

这篇关于Rails link_to方法:: delete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆