I took some time off to study up on Rails (using 2.3.8), work through a bunch of tutorials, make some simpler apps and I've now picked this project back up. I have most of the job done as far as generating static pages and the CRUD for categories, subcategories, groups and products for admin purposes. However I'm still having trouble displaying subcategories, groups and products in the catalog gallery. I can display categories fine, since I will always want to show all categories. But I want to be able to show one or more subcategories based on the category the person clicks on. And then on down the line: They would then click on a subcategory to see one or more groups in that subcategory and finally click a group to be shown the part detail page which lists one or more parts in a particular group. Right now I'm just trying to display the appropriate subcategory as the rest that follow will be basically the same thing (groups, products)
Each level of the catalog has a foreign key to it's parent with the appropriate relationships in the models:
category has_many :subcategories
subcategory belongs_to :category has_many :groups FK = category_id
group belongs_to :subcategory has_many :products FK = subcategory_id
product belongs_to :group FK = group_id
Here is my routes.rb
map.root :controller => 'pages'
# I was experimenting with this and could get it to display the appropriate subcategories, but only if I hand coded the catalog_id in my show_subcategory action
# map.connect '/catalog/subcategory/:category_id', :controller => 'catalog', :action => 'show_subcategory'
map.show_subcategory 'catalog/:category_id', :controller => 'catalog', :action => 'show_subcategory'
Here is the catalog controller action:
@subcategory = Subcategory.find(params[:category_id])
render( :partial => "show_subcategory", :collection => @subcategory )
Finally (whew!), this is the call from my navigation:
<li><%= link_to 'Cleats', show_subcategory_path(:category_id => 1), :class => 'nav_cleat' %></li>
The above returns undefined method `map' for #<Subcategory:0x103324c28>
I've tried a bunch of different things, but can't quite seem to get there.
Last edited by Kurtismonger (2011-06-19 14:57:37)