nested routes problem when using friendly_id with 2-sided marketplace app

I want to use Friendly_Id gem with the tutorial to make urls pretty. But When I created the Order scaffold and nested it under products. I edited the orders_controllers as per tutorial. It keeps giving me error "Could not find product without ID". I read the gem documentation. I also tried used friendly.find instead of find. But it doesnt work. Code in my Product Model: extend FriendlyId friendly_id :name, use: [:slugged, :finders] I am using product name as slug. I would like to know how to proceed further with Orders using friendlyId.

Posted about 4 years ago by Ryan
Posted about 4 years ago by Alex Yang

You need to use the following code to define your variable:
User.friendly.find(params[:id])

It's not clear to me whether you're trying to set up friendly_id for Orders or for Products, but you should make sure that you use this code in the corresponding controller file (orders_controller.rb for Orders, products_controller.rb for Products).

1
Posted about 4 years ago by Ryan

I have set up friendly_id for Products.
Routes are like this : localhost:3000/products/name

When i proceeded with linking Orders and products...
I can't do
localhost:3000/products/name/orders/new

It says can't find product without id.
Here are the screenshots of my product.rb, set_product method in product_controller, routes and order controller.
http://imgur.com/a/lCTD2

I am having issues with link-orders-listings-users-part-2 where you define @lisitng find params in new and create methods of Order_controller.

1
Posted about 4 years ago by Alex Yang

It's not clear to me whether you're having trouble with nesting resources or with friendly_id. If you're trying to do both at once, I recommend that you first nest resources, then set up friendly_id so you'll more easily tell the source of any errors. If the 'localhost:3000/products/name' URL structure is working for you, that means that friendly_id is setup properly. It would also help to see a screenshot of the actual error.

1