John Butler wrote:> Hi,
>
> In my blog i display a post. I want to display a link tot he previous
> post if there is 1 and a link tot he next post if there is one.
>
> So i have in my controller
>
> def post
> @post = Post.find(params[:id])
> @post_pages, @posts = paginate :posts, :per_page => 1
> render(:layout => false)
> end
>
> And the following code in post.rhtml
>
> <% if @post_pages.current.next %>
> <%= link_to ''nextitem'', :action =>
"post", :id =>
> @post_pages.current.next %>
> <% end %>
>
> <%= render :partial => "post", :object => @post %>
>
> I know the above code is wrong but that is sort of what i am looking
> for.
>
> Anyone help?
What you''ve included in your code is pretty close to what you need.
Just use the paginator method with :per_page set to 1, and then include
the boilerplate previous and next links in your view:
<%= link_to ''Previous page'', { :page =>
@post_pages.current.previous }
if @post_pages.current.previous %>
<%= link_to ''Next page'', { :page =>
@post_pages.current.next } if
@post_pages.current.next %>
Have you tried implementing it and found problems?
Jeff Coleman
--
Posted via http://www.ruby-forum.com/.