pager_controller.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. #---
  10. # Excerpted from "Agile Web Development with Rails, 4rd Ed.",
  11. # published by The Pragmatic Bookshelf.
  12. # Copyrights apply to this code. It may not be used to create training material,
  13. # courses, books, articles, and the like. Contact us if you are in doubt.
  14. # We make no guarantees that this code is fit for any purpose.
  15. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  16. #---
  17. Rails::Initializer.run do |config|
  18. config.gem 'will_paginate', :version => '~> 2.3.11',
  19. :source => 'http://gemcutter.org'
  20. end
  21. class PagerController < ApplicationController
  22. def populate
  23. User.delete_all
  24. ["Chris Pine",
  25. "Chad Fowler",
  26. "Dave Thomas",
  27. "Andy Hunt",
  28. "Adam Keys",
  29. "Maik Schmidt",
  30. "Mike Mason",
  31. "Greg Wilson",
  32. "Jeffrey Fredrick",
  33. "James Gray",
  34. "Daniel Berger",
  35. "Eric Hodel",
  36. "Brian Marick",
  37. "Mike Gunderloy",
  38. "Ryan Davis",
  39. "Scott Davis",
  40. "David Heinemeier Hansson",
  41. "Scott Barron",
  42. "Marcel Molina",
  43. "Brian McCallister",
  44. "Mike Clark",
  45. "Esther Derby",
  46. "Johanna Rothman",
  47. "Juliet Thomas",
  48. "Thomas Fuchs"].each {|name| User.create(:name => name)}
  49. 763.times do |i|
  50. User.create(:name => "ZZUser #{"%03d" % i}")
  51. end
  52. end
  53. def user_list
  54. @users = User.paginate :page => params[:page], :order => 'name'
  55. end
  56. end