I installed friendly_id
according to the instructions. And use it for products.
For show
i use:
@product = Product.friendly.find(params[:id])
And it works.
But I have a couple of question, on its use for other controllers.
In cart_item_controller
i use:
@cart_item = current_user.cart.cart_items.find_by(product_id: params[:product_id])
I changed it to:
@cart_item = current_user.cart.cart_items.friendly.find(params[:id])
But i get error
undefined method `friendly' for #<ActiveRecord::Associations::CollectionProxy []> Did you mean? friendly_id?
How do I properly replace this so that it works? Also, for comments i use:
def set_product
@product = Product.find(params[:product_id])
end
I tried replacing this with:
@product = Product.friendly.find(params[:id])
But getting an error:
Couldn't find Product without an ID