我想使用表数据旁边的链接删除存储在表中的记录。我想出的错误是:
没有路线匹配[GET]" / carlogs / destroy"
我的破坏方法:
def destroy
@carlog= CarLog.find(params[:id])
@carlog.destroy()
redirect_to show_path(@carlog)
end
包含删除链接的部分视图代码:
<% @carlogs.each do |car| %>
<tr>
<td><%= car.id %></td>
<td><%= car.plate_number %></td>
<td><%= car.brand %></td>
<td><%= car.slot_number %></td>
<td><%= car.is_taken %></td>
<td><%= car.created_at %></td>
<td><%= link_to "Delete", show_path(car), method: :delete, data:
{confirm: "Are you sure?"} %>
</tr>
<% end %>
答案 0 :(得分:1)
确保您拥有delete
REST方法:
DELETE /carlogs/:id(.:format) carlogs#destroy
在您的application.js
中,您必须拥有以下内容:
//= require jquery_ujs
答案 1 :(得分:0)
对销毁记录使用销毁链接,然后像
那样重定向表方法
def destroy
@carlog= CarLog.find(params[:id])
@carlog.destroy()
redirect_to show_path(@carlog) #-> Table pathe
end
的routes.rb
delete 'destroy' => 'carlogs#destroy'
查看
<%= link_to "Delete", destroy_path, method: :delete, data:
{confirm: "Are you sure?"} %>
我认为会帮助你
答案 2 :(得分:0)
你为什么写show_path(car)?
也许你的意思是car_path(汽车)?
<?php
include('includes/config.php');
session_start(); // Use session variable on this page. This function must put on the top of page.
if (!isset($_SESSION['admin_email'])) {
echo "<script>window.open('login.php','_self')</script>";
}
else
{
global $con;
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
$user = $_SESSION['admin_email'];
$ip = $_SERVER['REMOTE_ADDR'];
$update_last_login="UPDATE m_admins SET admin_status='ONLINE',admin_last_login='$date',active_ip_address='$ip' WHERE admin_email='$user'";
$update_last_login = mysqli_query($con, $update_last_login) or die (mysqli_error($con));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Demo App | Welcome </title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body class="skin-black">
<div class="user-panel">
<div class="pull-left info">
<p>Hello,
<?php if(isset($_SESSION['admin_email'])){
echo "".ucfirst($_SESSION['admin_name']);
}
?>
</p>
</div>
</div>
</body>
</html>
<?php
}
?>
另外,您应该检查路线<%= link_to "Delete", car_path(car), method: :delete, data:
{confirm: "Are you sure?"}%>
。
我认为这不会出现在[GET] "/carlogs/destroy