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?

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?

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

Fred

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?

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".

Ok, I make like this:

  @pages, specs = Spec\.paginate :specs,
    :page =&gt; 30,
    :order =&gt; &#39;last\_name, first\_name&#39;,
    :conditions =&gt; \[&quot;last\_name like ?&quot;, @initial\+&#39;%&#39;\]

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

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?

See http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/

Fred

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?

Kayne, you have a couple of choices:

  1. Use the will_paginate gem here:

http://github.com/mislav/will_paginate/tree/master

and

follow the notes here:

http://blog.railsspace.com/past/2008/1/31/railsspace_will_paginate/

  1. Use the class_pagination plugin here:

http://github.com/masterkain/classic_pagination/tree/master

Personally, I would recommend option (1) being that it works better for

moving search functionality into the model.

Good luck,

-Conrad

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