will_paginate problem

Hi,everybody I write a code like follow,the question was "paginate" has been drop until the rails 2.0,now we use "will_paginate" to replace it.But I don't know how to change my code to let it suitable.

The will_paginate’s paginate method creates both the instance variables and maintains them automatically. All you will need to do is :

@books = Book.paginage :page => parmas[:page], :per_page => 10, :include => [:authors, :publishers], :order => :id

You should check out railscasts.com episode 51, it demonstrates what you wish to do quite well.

Thanks & Regards, Dhruva Sagar.

Ted Turner - “Sports is like a war without the killing.”

Hi,Dhruva

Thank you for your help,but I still can’t pass my test.May be the code goes wrong .

try params[:page] instead of parmas[:page] Also if you have an error post the trace here

if we cant see the error … we cant see the problem

One thing that I forgot is that you will need to add the following to your view to create the page links

<%= will_paginate @books %>

Thanks & Regards, Dhruva Sagar.

Stephen Leacock - “I detest life-insurance agents: they always argue that I shall some day die, which is not so.”

Oh, thanks for pointing that out Adam, There is indeed a spellings mistake, it must be params[:page]

Thanks & Regards, Dhruva Sagar.

Marie von Ebner-Eschenbach - “Even a stopped clock is right twice a day.”

First,I want say sorry to Dhruva,because i didn’t write a test,it was a controller.When I run my Webrick and try to use controller like http://localhost:3000/catalog/index

it goes wrong,like this—>

C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in `method_missing_without_paginate'
C:/Ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing'

app/controllers/catalog_controller.rb:5:in `index'

So,what i do for thoes code

Ok it seems in a hurry to type I have made quite a few spelling mistakes, I will write it again (carefully) now, this is what you should have :

@books = Book.paginate :page => params[:page], :per_page => 10, :include => [:authors, :publishers], :order => :id

and in the view for the page links you will need :

<%= will_paginate @books %>

Please try the one I have mentioned above, this should work properly earlier I had misspelled paginate to paginage :-S. Sorry for those typos.

Thanks & Regards, Dhruva Sagar.

Mike Ditka - “If God had wanted man to play soccer, he wouldn’t have given us arms.”

It still goes wrong,

Now,we got a new problem,like this–>

When i change 'publishers' to 'publisher',now we got like follow

In the statement, it should be :order => ‘id’ and not :order => :id

Thanks & Regards, Dhruva Sagar.

Marie von Ebner-Eschenbach - “Even a stopped clock is right twice a day.”

We had got another failure–>

Hi,Dhruva

I had success with my code.Here is the code.

controller code–>

def index @page_title = “Book List” @books = Book.paginate :page => params[:page],

                        :per_page => 10,
                        :include => [:authors, :publisher],
                         :order => "[books.id](http://books.id) desc"

end view code →

Thanks a lot !You are good man.

Your welcome, glad it helped :).

Thanks & Regards, Dhruva Sagar.

Charles de Gaulle - “The better I get to know men, the more I find myself loving dogs.”