Hi I am beginner to ruby on rails. I have one category table and one product table. I want to display all category and onclick of category display all product related to that category. I am able to display all categories but I dont know how to pass category id to link of that category. I tried this in following way but its not working
in routes.rb
get "products", :to => "products#show"
and in view I am creating link to my category in following way
<%= link_to "category.name", products_path %>
its not giving any error but I don't know how to pass id.
I don't know how to do this? Is this the proper way to do this? Need help. Thank you.
<%= link_to "category.name", products_path(:product_id => product.id) %>
Then in your method you can access the value through:
params[:product_id]