The new version of will_paginate has abandoned this practice and switched to the gem method. This article builds an application named foobar to understand the usage of will_paginate.
====================================
C: \> rails foobar-d mysql
C: \> cd foobar
C: \ foobar> ruby script/generate scaffold article title: string content: text
In this case, set the database (C: \ foobar \ config \ database. yml) and make sure that the relevant database has been created.
C: \ foobar> rake db: migrate
C: \ foobar> ruby script/server
Now, you can browse http: // localhost: 3000/articles and add some data (such as 10) to prepare for paging.
====================================
The old version of will_paginate in the form of plugin does not need to be explicitly loaded in the rails program, because the init under the plug-in directory will be automatically executed when rails is started. rb file, and the new version of will_pagiante adopts the gem form, there is no such mechanism, so you need to explicitly load in the rails program:
# C: \ foobar \ config \ environment. rb
Rails: Initializer. run do | config |
Config. gem 'mislav-will_paginate',: version => '~> 2.3.2 ',: lib => 'will _ paginate ',
: Source => 'HTTP: // gems.github.com'
End
Restart WEBrick and run the following command to install the corresponding gem:
C: \ foobar> rake gems: install
The installation is complete.
Add the following code to modify the index method of the controller:
# C: \ foobar \ app \ controllers \ articles_controller.rb
@ Articles = Article. paginate: page => params [: page],: per_page => 2
Modify the corresponding template file and add code similar to the following:
# C: \ foobar \ app \ views \ articles \ index.html. erb
<% = Will_paginate @ articles %>
Restart WEBrick again, And Then browse to view the page effect.
====================================
Will_paginate latest document: http://github.com/mislav/will_paginate/wikis