Restul Controllers with multiple access points

I’m trying to solve the same problem outlined in this blog post by Tore Darell. Basically, what’s the best practice for having multiple access points to a nested resource:

class User < ActiveRecord::Base

has_many :posts

class Category < ActiveRecord::Base
has_many :posts

class Post < ActiveRecord::Base
belongs_to :user
belongs_to :category

This blog points out one method but I feel like creating a ton of different controllers is the cleanest method, any other thoughts?

I would say, as long as there's more similarities than differences in
the way you retrieve and present posts in the different contexts,
stick to doing it DRY, i.e. one controller and one set of views for
posts, and use private methods in the controller and helper methods in
the view to abstract away the complexity. For example, you could do
something like this in the controller:

class PostsController < ApplicationController
  before_filter :find_parent

  def index
    @posts = @parent ? @parent.posts.find(:all) : Post.find(:all)

  def find_parent
    @parent =
      if params[:category_id]
      elsif params[:user_id]