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 2) 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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rodrigo Fuentealba
2008-Sep-19 07:58 UTC
Re: Help with best approach(fairly easy question)
2008/9/19 elioncho <elioncho-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > 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 Fuentealba http://www.thecodekeeper.net/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---