2007/12/6, Nicolas Cavigneaux
<nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org>:> Hi all,
>
> I want to have a RESTful resource (because I need to use
atom_feed_builder).
>
> For the sake of the exemple, let say I need : map.resources :news
>
> I want to be able to list all the news in index action, paginate it
> (using will_paginate for example) and add cache to it each paginated
> page.
>
> To add cache I need to have url like news/page/2, urls like
> news/?page=2 can''t be cached page by rails.
>
> So any idea to solve this problem ?
The answer was "use fragment caching"
# Controller
def index
unless read_fragment({:page => params[:page] || 1}) # Add the
page param to the cache naming
@news = News.paginate :all, :page => params[:page]
end
end
# View
<% cache ({:page => params[:page] || 1}) do %>
... All of the html to display the posts ...
<% end %>
--
Nicolas Cavigneaux
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---