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 is not used in railsProgramIt is because the init under the plug-in directory is 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.
Modify the index method of the controller.Code:
# 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