Topic: will paginate error

Hello, I'm new in Ruby and I don't speak english very well. I'm programming in Easyeclipse RadRails. I'm trying to use the will paginate but I get the error "ActionView::TemplateError (undefined method 'current' for........). Here is part of my controller:

class ProductsController < ApplicationController
  def index
    @product_pages = Product.paginate(:page => params[:page],
                      :per_page => 10, :order => 'title DESC')
    @products = Product.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @products }
    end
  end

And this is the part of my view that throws the error:

<%= if @product_pages.current.previous
    link_to("Previous page", { :page => @product_pages.current.previous })
         end
%>

Thanks

Re: will paginate error

Best thing to do in this situation is to fire up the api for will_paginate:  i'm guessing that you're using the gem rather than the plugin version here. 

Start a gem server - at the command line, type
gem server

now, open a browser and go to localhost:8808, or wherever the gem server told you it had started up.

here you'll see a list of your installed gems.  I'm guessing you used "mislav-will_paginate" but whatever you used, go to the entry for that and click on the 'rdoc' link.  then click on 'WillPaginate::Collection".  You can see there that the attribute is 'current_page' not 'current'. 

I thought it would be better to show you how to find the answer yourself rather than just tell you smile

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: will paginate error

Max Williams wrote:

Best thing to do in this situation is to fire up the api for will_paginate:  i'm guessing that you're using the gem rather than the plugin version here. 

Start a gem server - at the command line, type
gem server

now, open a browser and go to localhost:8808, or wherever the gem server told you it had started up.

here you'll see a list of your installed gems.  I'm guessing you used "mislav-will_paginate" but whatever you used, go to the entry for that and click on the 'rdoc' link.  then click on 'WillPaginate::Collection".  You can see there that the attribute is 'current_page' not 'current'. 

I thought it would be better to show you how to find the answer yourself rather than just tell you smile

oh and there's another problem with your code:  current_page returns a number, which doesn't have a 'previous' method, so that will break if you call 'previous' on it.  If you want the previous page just say

    link_to("Previous page", { :page => @product_pages.previous_page })

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: will paginate error

Thanks!!!!