Paginate

How can you control what to list and what not to in a paginate?

@content_pages, @contents = paginate :contents, :per_page => 10

And how do I access any related data?

Pål Bergström wrote:

How can you control what to list and what not to in a paginate?

@content_pages, @contents = paginate :contents, :per_page => 10

And how do I access any related data?


Posted via http://www.ruby-forum.com/.

you can pass an :order or :conditions to the paginate function to limit
your results or sort them. The results are stored in the @contents
instance variable

_Kevin

_Kevin wrote:

P�l Bergstr�m wrote:

How can you control what to list and what not to in a paginate?

@content_pages, @contents = paginate :contents, :per_page => 10

And how do I access any related data?


Posted via http://www.ruby-forum.com/.

you can pass an :order or :conditions to the paginate function to limit
your results or sort them. The results are stored in the @contents
instance variable

_Kevin

Order I know of, and also that you can have conditions but not sure what
to put in there? Do you mean conditions as in a find? (sorry for a
possibly stupid question)

_Kevin wrote:

P�l Bergstr�m wrote:

How can you control what to list and what not to in a paginate?

@content_pages, @contents = paginate :contents, :per_page => 10

And how do I access any related data?


Posted via http://www.ruby-forum.com/.

you can pass an :order or :conditions to the paginate function to limit
your results or sort them. The results are stored in the @contents
instance variable

_Kevin

Conditions doesn’t give you the possibility to show the columns you
want, or?

Pål Bergström wrote:

Conditions doesn’t give you the possibility to show the columns you
want, or?

Any help with this is appreciated. I’m kind of stuck.

Conditions doesn’t give you the possibility to show the columns you
want, or?

The Paginator object does not contain your other objects. You need to
find them like so (from the api docs):

def list
@person_pages = Paginator.new self, Person.count, 10, params[:page]
@people = Person.find :all, :order => ‘last_name, first_name’,
:limit => @person_pages.items_per_page,
:offset => @person_pages.current.offset
end

One thing to watch out for is the Person.count. If you have conditions,
you’ll need to run a count query with those conditions first:

def list
conditions = [“people.last_name like ‘?%’”, params[:letter]]
count = Person.count(:all, :conditions => conditions)
@person_pages = Paginator.new(self, count, 10, params[:page])
@people = Person.find :all, :order => ‘last_name, first_name’,
:conditions => conditions,
:limit => @person_pages.items_per_page,
:offset => @person_pages.current.offset
end

Now, I’m reading the docs and it appears the above method is the classic
way to do it, and the same can now be achieved with:

def list
@person_pages, @people =
paginate :people,
:conditions => [“people.last_name like ‘?%’”,
params[:letter]]
:order => ‘last_name, first_name’
end

Anyone know from experience if this is so?

Curtis S. wrote:

Thanks Curtis :slight_smile:

I think I understand it better now. I should use

<%= @contents.each do |dada| %>

PÃ¥l,

It also appears that paginate will accept a :select parameter if you
want to specify columns.

Pål Bergström wrote:

Curtis S. wrote:

PÃ¥l,

It also appears that paginate will accept a :select parameter if you
want to specify columns.

That’s great. I’ll try it.

It works.

The only problem is that I get an error message saying columns are
missing. I assume it has to do with:

<% for column in Abc.content_columns %>

Is there a way to solve this?

Curtis S. wrote:

PÃ¥l,

It also appears that paginate will accept a :select parameter if you
want to specify columns.

That’s great. I’ll try it.