-1

错误:没有路线匹配 [GET] "/bookings/:id/%3E:format"

单击“link_to”的链接时,我想更新属性..

<%= link_to 'Cancel', '/bookings/:id/(.:format)' %>

路线.rb

put '/bookings/:id/(.:format)' => "bookings#tocancel"
patch '/bookings/:id/(.:format)' => "bookings#tocancel"

控制器

def tocancel
 @booking = Booking.find(params[:id])
 @booking.update_attribute(:status, "cancel")
 respond_to do |format|
  format.html { redirect_to @booking, notice: 'Booking was successfully cancelled.' }
  format.json { render :show, status: :ok, location: @booking }

结尾

4

1 回答 1

0

在预订控制器中创建一个方法:

def tocancel
 @booking = Booking.find(params[:id])
 @booking.update_attribute(:status, "cancel")
 respond_to do |format|
  format.html { redirect_to @booking, notice: 'Booking was successfully cancelled.' }
  format.json { render :show, status: :ok, location: @booking }
 end
end

路线将是:

resources :bookings do
  member do
   get :tocancel
  end
end

取消链接可以创建为:

link_to "Cancel", tocancel_booking_path(booking.id)

在这里,您应该将 booking_id 传递给取消链接。现在检查您如何在放置此取消链接的页面上获得 booking_id。让我知道是否有任何问题。

于 2016-06-30T10:35:49.663 回答