錯誤:沒有路由匹配[GET]「/預訂/:ID /%3E:格式」的Rails:路由錯誤,而試圖通過的link_to更新屬性
我想更新的屬性時點擊的「鏈接的link_to」 ..
<%= link_to 'Cancel', '/bookings/:id/(.:format)' %>
的routes.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 }
端
您不會將URL格式傳遞給link_to。您可以使用助手方法bookings_path並傳遞@booking對象。閱讀關於它的(優秀的)文檔:http://guides.rubyonrails.org/routing.html – MrWillihog
'<%= link_to'取消','complete_url/bookings/pass_id_value_here'%>'在id:地點。 –
<%= link_to'取消',tocancel_booking_path(預訂)%>錯誤:沒有路由匹配[GET]「/ bookings/36/tocancel」 –