[英]ruby on rails - unable to delete (destroy)
I am unable to delete a record in ruby on rails for some reason. 由于某种原因,我无法删除ruby中的记录。 I have tried many solutions unfortunately to no avail. 不幸的是,我尝试了许多解决方案都无济于事。 (such as How to delete / destroy a record in rails? ) (例如, 如何在Rails中删除/销毁记录? )
The contents of my application.erb
are: 我的application.erb
的内容是:
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
when i open in html it only displays the following css it does not display js as in the tags above. 当我打开html时,它仅显示以下CSS,而不显示js,如上面的标记中所示。
<link data-turbolinks-track="true" href="/assets/scaffolds.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/statuses.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
for my index.html.erb
对于我的index.html.erb
<h1>Listing statuses</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @statuses.each do |status| %>
<tr>
<td><%= status.name %></td>
<td><%= status.content %></td>
<td><%= status.id %></td>
<td><%= link_to 'Show', status %></td>
<td><%= link_to 'Edit', edit_status_path(status) %></td>
<td><%= link_to 'Destroy', status , method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Status', new_status_path %>
i am troubleshooting this currently to no avail, if someone can pick any faults in this code, i would greatly appreciate. 我目前无法对此进行故障排除,如果有人可以在此代码中发现任何错误,我将不胜感激。 :) the js files are not showing in the head section of the page and the destroy function is not working, let alone the confirm tag. :) js文件未显示在页面的顶部,并且destroy函数无法正常工作,更不用说确认标签了。
Update : Now I am getting this error: 更新 :现在我收到此错误:
TypeError: Object doesn't support this property or method Rails.root: [location] TypeError:对象不支持此属性或方法Rails.root:[位置]
if i remove the ' <%= javascript_include_tag %>
' it functions, although not fully (ie. does not delete like in the first instance) 如果我删除了“ <%= javascript_include_tag %>
”,它会起作用,尽管不能完全消除(即不会像第一个实例那样删除)
update 2 when i click on destroy button, it simply redirects me to view that particular status only, it does not destroy 更新2当我单击销毁按钮时,它只是将我重定向到仅查看该特定状态,而不会销毁
update 3 inside the application.js
i have the following: 在application.js
内部更新3我有以下内容:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
update 4 I have changed the <%= javascript_include_tag %>
to <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
and it loads the js file however when i click on that js file from the sourcecode i get a routing error. 更新4我已经将<%= javascript_include_tag %>
更改为<%= javascript_include_tag %>
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
并且它加载了js文件,但是当我从源代码中单击该js文件时我收到路由错误。 Any possible way i can solve that? 有什么办法可以解决这个问题?
Inside application.erb
, you need to include your application.js
file with javascript_include_tag
like this: 在application.erb
内部,您需要使用javascript_include_tag
包含application.js
文件,如下所示:
<%= javascript_include_tag 'application' %>
Assuming you have jquery
and jquery_ujs
set inside your application.js
假设你已经jquery
和jquery_ujs
设置你的内部application.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.