I am new in RoR.
The problem is, I created fully functional product categorization with Ancesrty. But now I want to be able to retrieve products that is under these subcategories.
This is my categories show controller
@category = Category.find(params[:id])
Here is categories#show view.
<b>Name of the category:</b>
<%= @category.name %>
<div class="product"
</div>
</p>
<% unless @category.children.empty? %>
<ul id="sub-menu">
<% @category.children.each do |sub1| %>
<%= link_to (sub1.name), sub1 %>
<%end%>
<%end%>
It all works fine. but now I want to add in view categories/show function that shows all products that is under that category.
I added such code. In category/show controller
@cat_id = @category.id
@product = Product.where("category_id = ?",@cat_id)
In the categories show view I added
<td><%= @product.name %></td>
Then clicking on some subcategory where should appear few products, there just shows up Product
To check if the code is right I put in the console. There it works fine and retrieve products related to this category.
I dont understand why then code not working in webserver when I launch application ?
Could it be because of some erorr in Associations ?
Thanks !