Topic: Pagination related question...

Hey guys,

I have the following code in my controller:

def list
    @total_device_number = Device.find(:all)
    @page_title = 'Listing Devices'
    sort_by = params[:sort_by]
    @device_pages, @devices = paginate :devices,
                                                :order => sort_by,
                                                :per_page => 20
end

In list.rhtml, I have a line of code that fetches the total no: of devices in the db:

<%= @total_device_number.size %>

When I attempt the following in list.rhtml instead,

<%= @devices.size %>

I end up getting the number of devices for a particular page...maximum of twenty obviously. Is there a way for me to get rid of the @total_device_number instance variable, and instead use the @devices instance variable to get a comprehensive listing? Thank you very much for you time. smile

http://www.webyfi.com
It's not the size of the app that matters, it's how you code it. ~ railsenvy

Re: Pagination related question...

The @devices variable is just an array of the items which will be displayed on the page, so you can't get a count of all items this way.

However, you can through the paginator (IIRC). Try this.

<%= @device_pages.item_count %>

Untested.

Railscasts - Free Ruby on Rails Screencasts

Re: Pagination related question...

Hey that works perfectly! Thanks a lot Ryan! smile

http://www.webyfi.com
It's not the size of the app that matters, it's how you code it. ~ railsenvy