简体   繁体   English

Rails 4 link_to控制器的更新方法

[英]Rails 4 link_to update method of controller

I'd like to create a link to the update method of the reservations controller and update the value of one field. 我想创建一个到Reservations控制器的update方法的链接,并更新一个字段的值。 In my view, I have: 我认为,我有:

tbody
- @reservations.each do |reservation|
  tr
    td =reservation.name
    td =reservation.phone
    td =reservation.email
    td.center =link_to 'Complete', reservations_path(reservation, fulfillment_time: @user.location.current_time),\
        method: :put, class: 'fulfill-now'

But, the link isn't being generated to the update method. 但是,并未生成到update方法的链接。 Instead it's 而是

http://localhost:3000/reservations.3?fulfillment_time=03%3A38+PM http:// localhost:3000 / reservations.3?fulfillment_time = 03%3A38 + PM

I'm thinking it should be 我在想应该

http://localhost:3000/reservations/3?fulfillment_time=03%3A38+PM http:// localhost:3000 / reservations / 3?fulfillment_time = 03%3A38 + PM

Any suggestions? 有什么建议么?

要链接到更新操作,应使用reservation_path (单数)而不是reservations_path

instead this line: 代替这一行:

td.center =link_to 'Complete', reservations_path(reservation, fulfillment_time: @user.location.current_time),\

try this :) 尝试这个 :)

td.center =link_to 'Complete', reservation_path(reservation, fulfillment_time: @user.location.current_time),\

I recommend you using command rake routes in terminal to see how your routes exactly looks. 我建议您在终端中使用命令rake routes ,以查看路径的外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM