leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 215 forks source link

How to ignore will paginate gem issue? #280

Closed vedsingh-fullstack closed 8 years ago

vedsingh-fullstack commented 8 years ago

Hi , I have will_paginate gem installed and used many places but with wice grid update it is giving undefined method `per' error. Is there any way to ignore will paginate without removing from gemfile.

leikind commented 8 years ago

if you search for will_paginate on https://github.com/leikind/wice_grid you will find this:

WARNING: Since 3.2.pre2 WiceGrid is not compatible with will_paginate because internally it uses kaminari for pagination, and kaminari is not compatible with will_paginate!

kodujeme commented 8 years ago

Why is this closed? I have very same issue - yes there is warning in documentation, but I need workaround for using wice_grid in existing project.

leikind commented 8 years ago

The answer to your question is right above your question:

Since 3.2.pre2 WiceGrid is not compatible with will_paginate because internally it uses kaminari for pagination, and kaminari is not compatible with will_paginate!

kodujeme commented 8 years ago

Yuri, thank you for your contribution to open-source community, I appreciate it and wice_grid is a really great help for everyone who needs complex grid. However, you do not read issues properly, showing me the paragraph I already read before is not solution for this problem.

I found working solution by putting this code to initializers:

if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        def per(value = nil)
          per_page(value); self
        end
        def total_count()
          count
        end
        def first_page?()
          self == first
        end
        def last_page?()
          self == last
        end
      end
    end
    module CollectionMethods
      alias_method :num_pages, :total_pages
    end
  end
end
leikind commented 8 years ago

If I understand correctly, you will_paginate is used in your project. How is it a solution to override will_paginate methods by, as I guess, Kaminari methods? You are marrying Kaminari and will_paginate. Are you sure you haven't broken pagination in your project?

And at the end of the day this is not even a WiceGrid issue. What you are trying to do is a project with Kaminari and will_paginate working together.

kodujeme commented 8 years ago

I absolutely agree with you, but wouldn't be great to have workaround for everyone who wants use your grid and can't get a rid of will_paginate?

The solution I posted before seems to work seamless, I am still in testing phase.

However I have one problem with your "Ugly monkey-patching Kaminari": Kaminari has "params_on_first_page" parameter for displaying page parameter on first page and your monkey patching ignores it

current_page_params_as_query_string = @param_name.to_s + '=' + (page <= 1 ? nil : page).to_s https://github.com/leikind/wice_grid/blob/rails3/lib/wice/kaminari_monkey_patching.rb#L8

https://github.com/amatsuda/kaminari/blob/master/lib/kaminari/helpers/tags.rb#L43

So link in pagination for the first page is with page param but without value and I get invalid value for Integer(): ""

leikind commented 8 years ago

Monkey patching is evil.