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)
end
private
def find_parent
@parent if params[:category_id]
Category.find(params[:category_id])
elsif params[:user_id]
User.find(params[:user_id])
end
end
end
On May 18, 5:29 pm, "blinking bear"
<blinkingb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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:
>
> IE:
> class User < ActiveRecord::Base
> has_many :posts
> end
>
> class Category < ActiveRecord::Base
> has_many :posts
> end
>
> class Post < ActiveRecord::Base
> belongs_to :user
> belongs_to :category
> end
>
> This blog points out one method but I feel like creating a ton of different
> controllers is the cleanest method, any other thoughts?
>
> http://tore.darell.no/entries/2-cleaning-up-your-nest-how-to-nest-res...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---