简体   繁体   中英

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:

http://localhost/cars/175

I'd like to add two url parameters to this link

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

Is it possible?

You will need to use the explicit path generation, using 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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