# Help with best approach(fairly easy question)

**URL:** <https://www.ruby-forum.com/t/help-with-best-approach-fairly-easy-question/149006>\
**Category:** Rails\
**Created:** [September 19, 2008, 10:02am UTC](https://www.ruby-forum.com/t/help-with-best-approach-fairly-easy-question/149006 "2008-09-19T10:02:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [September 19, 2008, 10:02am UTC](https://www.ruby-forum.com/t/help-with-best-approach-fairly-easy-question/149006/1 "2008-09-19T10:02:29Z")

</div>

Hello!

Well this is maybe a fairly easy question. I am writing an app where  
users that belong to a group have their own blog where they can make  
posts. I have a posts\_controller with all the CRUD operations and my  
index action shows all the posts from all the users on a group. The  
route is:

users/1/posts

The thing is that I want to show too, all the posts from any user, or  
all the posts for a given tag or category. So my question is, which  
option should I use:

1. Should I send some extra parameters to my index action, like and id  
or something:

users\_posts(user.id,{:category =\> 1})

and check on the controller which posts should be shown (for a user,  
group, tag, category etc…)

Something like this:

def index  
if params[:category]  
@posts = Posts.find(:all, :conditions =\> ["category\_id = ?,  
params[:category]])  
elsif params[:user]  
@posts = Posts.find(:all, :conditions =\> ["user\_id = ?,  
params[:user\_id]])  
elsif params[:tag]  
.  
.  
.  
end

1. Should I create different controllers with only an index action on  
it (Create and other actions stay on the posts\_controller):

post\_categories controller? post\_tags controller? user\_posts  
controller?

So, which approach should I use?

Thanks again,

Elioncho

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [September 19, 2008, 10:03am UTC](https://www.ruby-forum.com/t/help-with-best-approach-fairly-easy-question/149006/2 "2008-09-19T10:03:40Z")

</div>

2008/9/19 elioncho [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hello!
> 
> 1. Should I send some extra parameters to my index action, like and id  
> or something:
> 
> 2. Should I create different controllers with only an index action on  
> it (Create and other actions stay on the posts\_controller):
> 
> So, which approach should I use?

I think you should use your first. It’s a bit more coding, but you  
have your code in just one controller, so you can modify only one part  
and not a lot of actions, controllers et al.

Cheers!

–  
Rodrigo F.  
[http://www.thecodekeeper.net/](http://www.thecodekeeper.net/)
