A big paginate plugin problem

Hi,

I’ve got big problem. I was looking google for some info, but
unfortunately, no solutions help me.
So, my problem is:

I’ve got this code:

 @pages, specs = paginate :specs,
   :conditions => ["last_name like ?", @initial+'%'],
   :order => "last_name, first_name",
   :per_page => 30
  @users = specs.collect { |spec| spec.user }

But it doesn’t work properly. I think: It is normal, because of new
version of Rails (2.0 and higher), where paginate is plugin now. So i
installed will_paginate by this way:

 gem install mislav-will_paginate

(gem install will_paginate doesn’t work too!)

And added on the end (after “end” word) in config/enviroment.rb:

 require 'will_paginate'

And at least I’m looking…

Crash. Error like this:

NoMethodError in CommunityController#index

undefined method `paginate’ for #CommunityController:0x49985b4

And now, I don’t know what to do. Any solutions?

On Aug 10, 7:07 pm, Kayne [email protected] wrote:

undefined method `paginate’ for #CommunityController:0x49985b4

And now, I don’t know what to do. Any solutions?

Have you tried looking at the will_paginate examples at
gitrdoc.com ?

Fred

Yes, but I didn’t understand this… I’m newb. I use now RailsSpace
book.
Will you so cool and translate to me: How can I change my code for
will_paginate, please?

RailsSpace is clearly outdated and that old “paginate” method should
not be used anymore. You’re better served getting a newer book like
the latest “Agile web development with Rails”.

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

Ok, I make like this:

  @pages, specs = Spec.paginate :specs,
    :page => 30,
    :order => 'last_name, first_name',
    :conditions => ["last_name like ?", @initial+'%']

And when I want to execute this code. browser gives me back:

Couldn’t find Spec with ID=1 AND (last_name like ‘B%’)

I don’t know, what exactly it’s saying… I just want to paginate rows
from model Spec (which one is belongs_to :user), to show users from
databases. In Spec model I’ve got first_name and last_name and by
ActiveRecord this is belong to User model.

But now I’ve got problem - how it show by will_paginate?

On Aug 10, 9:24 pm, Kayne [email protected] wrote:

Yes, but I didn’t understand this… I’m newb. I use now RailsSpace
book.
Will you so cool and translate to me: How can I change my code for
will_paginate, please?

It’s pretty simple. Your models gain a paginate method that is pretty
much exactly the same as find (it takes the same options
(:conditions, :order and so on) except that it also takes a :page and
a :per_page option and loads only the relevant records.

Fred

On Aug 10, 10:36 pm, Kayne [email protected] wrote:

And here I have not any idea, how use will_paginate. Can you shot me a
solutions?

See

Fred

Yeah, you right. But who will pay for it? :wink:

Ok, I made it. I’m go to… the next problem :wink:

I don’t know… I hope you can help me. I’ve got that code:

if params[:q]
  query = params[:q]
  # Najpierw wyniki spo¶ród u¿ytkowników...
  @users = User.find_with_ferret(query, :limit => :all)
  # ... a nastêpnie podwyniki
  specs = Spec.find_with_ferret(query, :limit => :all)
  faqs = Faq.find_with_ferret(query, :limit => :all)

  # Teraz po³±cz w jedn± listê oddzielnych 

u¿ytkowników,posortowan± wed³ug nazwisk
hits = specs + faqs
@users.concat(hits.collect { |hit| hit.user}).uniq!
# Sortuj wg. nazwiska (wymaga specyfikacji dla ka¿dego
u¿ytkownika)
@users.each { |user| user.spec ||= Spec.new }
@users = @users.sort_by { |user| user.spec.last_name }
end

And here I have not any idea, how use will_paginate. Can you shot me a
solutions?

On Mon, Aug 10, 2009 at 11:07 AM, Kayne [email protected] wrote:

  :conditions => ["last_name like ?", @initial+'%'],

(gem install will_paginate doesn’t work too!)

undefined method `paginate’ for #CommunityController:0x49985b4

And now, I don’t know what to do. Any solutions?

Kayne, you have a couple of choices:

  1. Use the will_paginate gem here:

    GitHub - mislav/will_paginate: Pagination library for Rails and other Ruby applications

    and

    follow the notes here:

    Railsspace.com is for sale | HugeDomains

  2. Use the class_pagination plugin here:

    GitHub - masterkain/classic_pagination: Class pagination plugin for Rails. Hard to find ancient and dead stuff.

Personally, I would recommend option (1) being that it works better for
moving search functionality into the model.

Good luck,

-Conrad

On Aug 10, 9:50 pm, Kayne [email protected] wrote:

Ok, I make like this:

  @pages, specs = Spec.paginate :specs,
    :page => 30,
    :order => 'last_name, first_name',
    :conditions => ["last_name like ?", @initial+'%']

And when I want to execute this code. browser gives me back:

Look at the will_paginate docs a little more closely. The paginate
method returns a single object and (unlike the old paginate) you don’t
pass it an argument to tell it what to paginate. That error message
doesn’t look like something that will_paginate would raise though.

Fred

Oh yeah, thank you very much!
I see I have a lot of to learn yet.