Created
July 6, 2011 13:36
-
-
Save senny/1067232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Routes | |
# To prevent too deep nesting, we make the show, edit, update and destroy actions not nested under the category. We have a lot of models nested inside the product. | |
resources :category do | |
resources :products, :only => [:new, :create, :index] | |
end | |
resources :products, :only => [:show, :edit, :update, :destroy] | |
# ProductController | |
# We need to expose :category, :products and :product | |
class ProductController < ApplicationController | |
expose(:category) { | |
if params[:category_id].present? | |
Category.find(params[:category_id]) | |
else | |
product.category | |
end | |
} # to support the half-nested half-unnested Routes setup above we have to fetch the category depending on the url-param | |
expose(:products) { category.products } # for the #index action | |
expose(:product) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment