Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # CerealPagination: Demeter's Revenge for will_paginate.
  2. #
  3. # For every has_many :foos association, creates a paginate_foos
  4. # method which calls foos.paginate.
  5. #
  6. # TODO: Support has_and_belongs_to_many.
  7.  
  8. module CerealPagination
  9. def self.included(base)
  10. base.instance_eval do
  11. class << self
  12. def has_many_with_cereal_pagination(association_name, *args)
  13. has_many_without_cereal_pagination(association_name, *args)
  14. define_method("paginate_#{association_name}") do |*args|
  15. send(association_name).paginate(*args)
  16. end
  17. end
  18. alias_method_chain(:has_many, :cereal_pagination)
  19. end
  20. end
  21. end
  22. end
Add Comment
Please, Sign In to add comment