Monday August 03, 2009
TOTD #88: How add pagination to Rails - will_paginate
This Tip Of The Day (TOTD) explains
how to add pagination to your Rails application.
| ~/samples/jruby
>~/tools/jruby/bin/jruby
-S rails paginate ~/samples/jruby/paginate >~/tools/jruby/bin/jruby script/generate scaffold book title:string author:string ~/samples/jruby/paginate >sed s/'adapter: sqlite3'/'adapter: jdbcsqlite3'/ <config/database.yml >config/database.yml.new ~/samples/jruby/paginate >mv config/database.yml.new config/database.yml ~/samples/jruby/paginate >~/tools/jruby/bin/jruby -S rake db:migrate |
| #
Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: title: Ultramarathon Man Confessions of an All-Night Runner author: Dean Karnazes two: title: My Life on the Run author: Bart Yasso three: title: 50/50 Secrets I Learned Running 50 Marathons in 50 Days author: Dean Karnazes four: title: Born to Run author: Christopher Mcdougall five: title: Four Months to a Four-hour Marathon author: Dave Kuehls six: title: Galloway's Book on Running author: Jeff Galloway seven: title: Marathoning for Mortals author: John Bingham and Jenny Hadfield eight: title: Marathon You Can Do It! author: Jeff Galloway nine: title: Marathon The Ultimate Training Guide author: Hal Higdon ten: title: Running for Mortals author: John Bingham and Jenny Hadfield |
| ~/samples/jruby/paginate
>~/tools/jruby/bin/jruby
-S rake db:fixtures:load (in /Users/arungupta/samples/jruby/paginate) |
| ~/samples/jruby/paginate
>~/tools/jruby/bin/jruby
-S glassfish -l Starting GlassFish server at: 129.145.132.8:3000 in development environment... Writing log messages to: /Users/arungupta/samples/jruby/paginate/log/development.log. . . . Jul 29, 2009 2:06:44 PM com.sun.grizzly.scripting.pool.DynamicPool$1 run INFO: New instance created in 7,488 milliseconds |

| /tools/jruby
>./bin/jruby -S gem install will_paginate JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed will_paginate-2.2.2 1 gem installed Installing ri documentation for will_paginate-2.2.2... Installing RDoc documentation for will_paginate-2.2.2... |
| require "will_paginate" |
| @books
= Book.paginate(:page => params[:page], :per_page => 5) #@books = Book.all |
| <%= will_paginate @books %> |


Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Today's Page Hits: 4192
Total # blog entries: 1002