REST + Pagination + Caching

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 ?

Thanks.

Nicolas C.

2007/12/6, Nicolas C. [email protected]:

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 C.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs