【发布时间】:2016-06-30 10:24:02
【问题描述】:
错误:没有路线匹配 [GET] "/bookings/:id/%3E:format"
我想在单击“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 对象。阅读有关它的(优秀)文档:guides.rubyonrails.org/routing.html
-
<%= link_to 'Cancel', 'complete_url/bookings/pass_id_value_here' %>在:id地方传递 id 值。 -
错误:没有路线匹配 [GET] "/bookings/36/tocancel"
标签: ruby-on-rails ruby routes link-to update-attribute