简体   繁体   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")

This makes a link with href: 这与href链接:

http://localhost/cars/175 http:// localhost / cars / 175

I'd like to add two url parameters to this link 我想在此链接中添加两个网址参数

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

Is it possible? 可能吗?

You will need to use the explicit path generation, using car_path : 您将需要使用显式路径生成,使用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")

Note that I also replaced action with task . 请注意,我也用task替换了action action is reserved by Rails for the internal router, therefore you can't pass a parameter called action or it will conflict with the router. Rails为内部路由器保留了action ,因此您不能传递名为action的参数,否则它将与路由器冲突。

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

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