I am just beginning to build my Rails application and thus far I've followed a RESTful design and it's proven much easier to understand and organize the code and structure of the application. I have things like posts and comments. However for the front page. I want to display all the latest posts but also may be in the sidebar display things such as Latest Comments and Latest events. What's the best way to go about this while maintaining the RESTful philosophy?
+1
A:
Hi Randuin,
You can do something like this
first create 3 methods to display events, posts and comments. You might create an action like list and pass the number of days to select
Ex: http://localhost:3000/comments/list/10
will return a list of comments for last 10 days
And in your home page you can render them as components
render_component :controller => 'posts', :action => 'list', id => 10 like wise...
and make sure you add the list method to routes
Ex: map.resources :posts, :collection => {:list => :get} map.resources :events, :collection => {:list => :get} map.resources :comments, :collection => {:list => :get}
This is a one way I can think of, hope this helps
cheers, sameera
sameera207
2010-06-09 03:59:55