简体   繁体   中英

Error with Routes in Ruby on Rails

I have a problem with Routes in RoR. I create a route with parameters and when I create the link passing an object I have an error.

That's my routes.rb

get 'products_test/:type_data_type/:id', to: 'products#show', as: :product_front_test

And when I create the link:

link_to 'Click here', product_front_test_path(product)

I have the error:

No route matches {:action=>"show", :controller=>"products", :type_data_type=>#<Product id: 19, title: .....

You need to pass the param values type_data_type and id as argument for the product_front_test_path path as below:

link_to 'Click here', product_front_test_path(type_data_type: product.type_data_type, id: product.id)

Also, make sure this route product_front_test is before the show action in the routes.rb file if you have any.

您必须为此路由器的type_data_typeid设置两个参数,如下所示:

product_front_test_path(product.type_data_type, product)

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