Topic: Paginate method

Am new and working on that "Aha!" moment.

I generated CRUD methods via scaffold and was a bit thrown by:

def list
    @hotel_pages, @hotels = paginate :hotels, :per_page => 10
  end

Figured "paginate" must be a method that does something like @hotels = hotel.find :all
plus some sort of pagination.

However, I'm thrown by the syntax @hotel_pages, @hotels....

What is going on with the comma?  How do these two elements relate to each other?  Is this common?

Thanks for any explication you can provide.

Charlie

Re: Paginate method

Basically paginage returns an array.  @hotels is the collection of model objects that is your result, and @hotel_pages is a Paginator object that contains methods for finding things like, what page you're on, etc.

http://api.rubyonrails.org/classes/Acti … ml#M000108

Re: Paginate method

This is called multiple assignment. In a sense the method returns multiple values. This isn't used often, but can sometimes be useful. See the last question on this page for further information.

Railscasts - Free Ruby on Rails Screencasts

Re: Paginate method

Thanks to you both for your help. I think I've got a handle on this.

(I find it kind of amusing that all of the tutorials do something, say "wasn't that easy?", and then only later you look more closely and see something more or less inexplicable.  The answer to such things is usually found in the middle of a paragraph on page 274 of Agile Web Development with Rails, but you have to find it by pure luck or similar.  Ugh.)

Onward and upward.

Charlie

Re: Paginate method

cellmaker wrote:

Thanks to you both for your help. I think I've got a handle on this.

(I find it kind of amusing that all of the tutorials do something, say "wasn't that easy?", and then only later you look more closely and see something more or less inexplicable.  The answer to such things is usually found in the middle of a paragraph on page 274 of Agile Web Development with Rails, but you have to find it by pure luck or similar.  Ugh.)

Onward and upward.

Charlie

I totally hear you Charlie.  We all seem to forget that, in the beginning, none of this made sense to any of us.