【发布时间】:2020-03-11 03:09:22
【问题描述】:
我正在尝试销毁我的 Booking 表的一列。
我在 courses_controller.rb 中有一个连接表的索引,如下所示:
@bookings = Booking.joins(:schedule).where(user_id: current_user.id).where("schedules.status_id = ?", 11).page(params[:page]).per(5)
在视图中:
<% @bookings.each.with_index(1) do |b, index| %>
<tr>
<th>
<small><%= index %></small>
</th>
<td>
<small><%= b.schedule.available.strftime("%b %e, %I:%M %p") %></small>
</td>
<td>
<small></small>
</td>
<td>
<small><%= b.schedule.tutor.name %></small>
</td>
<td>
<span class="badge badge-pill badge-warning text-white text-capitalize">
<%= b.schedule.status.name %>
</span>
</td>
<td>
<%= link_to "Cancel request", users_bookings_path(b), method: :delete, data: {confirm: "Are you sure?"}, class: "btn btn-light btn-sm text-color-3 border" %>
</td>
</tr>
<% end %>
在booking_controller.rb中,我有方法销毁:
class Users::BookingsController < ApplicationUserController
before_action :find_request, only: :destroy
def destroy
@request.destroy
flash[:info] = "Success cancel request"
redirect_to users_requested_classes_path
end
private
def booking_params
params.permit(:user_id, :status_id, :schedule_id)
end
def find_request
@request = Booking.find(params[:id])
end
end
还有我的路线:
resource :bookings, only: :destroy
这是网络服务器控制台日志:
当我点击取消请求按钮时,它显示“找不到没有 ID 的预订”。为什么?
【问题讨论】:
-
请显示从收到请求到出现错误的整个 Web 服务器控制台日志。我们需要查看您的参数等。
-
完成。我已经更新了@Beartech 的帖子
-
欢迎来到 SO!请阅读“How to Ask”,尤其是“拼写、语法和标点符号很重要!”部分。 SO 不是留言板或论坛,它更像是一本语法很重要的在线参考书。 “我” => “我”,
shows Couldn't find... ID=>shows "Couldn't find... ID"。我们花在编辑上的时间比我们必须帮助回答问题的时间少了。另外,请阅读“Discourage screenshots of code and/or errors”。
标签: ruby-on-rails ruby activerecord ruby-on-rails-5