我有一个预订量上升,当你预约则自动将您预订的状态为“待定主机验证”。当你接受预定的订单管理变更确认(这是可以正常使用),并拒绝时,它应该将状态更新为已取消。当你点击其中有“取消”状态“拒绝”它回滚,更新不起作用。
下面是我的链接代码,索引页:
<li><%= link_to "Accept", my_booking_path(booking, booking: {status: "Confirmed"}), method: :patch, class: "btn btn-success" %></li>
<li><%= link_to "Decline", my_booking_path(booking, booking: {status: "Cancelled"}), method: :patch, class: "btn btn-danger" %></li>
我的模型是:
class Booking < ApplicationRecord
belongs_to :user
belongs_to :bed
has_one :review, dependent: :destroy
validates :checkin_on, presence: true
validates :checkout_on, presence: true
validates :status, inclusion: { in: ["Pending guest request", "Pending host validation", "Confirmed", "Cancelled"], allow_nil: true }
end
我在Bookings Controller上的更新操作:
def update
set_booking
@booking.update(set_params)
redirect_to my_bookings_path
end
参数为:
def set_params
params.require(:booking).permit(:status)
end
我如何能够实现这一点,以便它停止滚动回来?任何帮助或见解将不胜感激。谢谢!
答案 0 :(得分:2)
在包含块之外尝试allow_nil
,如下所示:
validates :status, inclusion: { in: ["Pending guest request", "Pending host validation", "Confirmed", "Cancelled"] }, allow_nil: true
您也可以如上所述在包含块之外使用allow_blank: true
...