簡體   English   中英

Ruby on Rails-具有url參數的Link_to對象

[英]Ruby on Rails - Link_to object with url parameters

= link_to("Paint orange", Car.find_by(user_id: current_user.id, 
                              acquaintance_id: user.id), 
                                       method: :patch, 
                                       remote: true, class: "btn btn-default")

這與href鏈接:

http:// localhost / cars / 175

我想在此鏈接中添加兩個網址參數

http:// localhost / cars / 175?action = paint&color = orange

可能嗎?

您將需要使用顯式路徑生成,使用car_path

= link_to("Paint orange", car_path(Car.find_by(user_id: current_user.id, acquaintance_id: user.id), task: "paint", color: "orange"), method: :patch, remote: true, class: "btn btn-default")

請注意,我也用task替換了action Rails為內部路由器保留了action ,因此您不能傳遞名為action的參數,否則它將與路由器沖突。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM