So you’ve got a ProductsController and UserProductsController? If so, then this could be a good way to go.
If the views are the same for user products and all products than having one controller and one set of views is a better solution.
The routes would be:
map.resources :users do |users|
users.resources :products, :name_prefix => “user_”
end
map.resources :products
And in actions you would have something like:
def index
params[:user_id].nil? ? Products.find(:all) : User.find(params[:user_id]).products
end
You could also extract the condition to a before_filter, let me know if you have any problems with this…
I actually needed to use the same views so this works perfectly. I
ended up using an if/else loop because I needed to render one
different view.
Thanks!
(now I have to go back and delete all the user_products files .....)
I actually needed to use the same views so this works perfectly. I
ended up using an if/else loop because I needed to render one
different view.
Thanks!
(now I have to go back and delete all the user_products files .....)