From b7693e6b9f20d5745a413d89cc9e6ecc9a8e28e6 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Mon, 25 Jul 2016 15:16:10 +0300 Subject: [PATCH 1/2] Fix will paginate with ActionController::Parameters --- lib/bootstrap_pagination/action_view.rb | 7 +++++++ .../fix_symbolize_update.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/bootstrap_pagination/fix_symbolize_update.rb diff --git a/lib/bootstrap_pagination/action_view.rb b/lib/bootstrap_pagination/action_view.rb index 15b1649..5bdde6e 100644 --- a/lib/bootstrap_pagination/action_view.rb +++ b/lib/bootstrap_pagination/action_view.rb @@ -1,9 +1,16 @@ require "will_paginate/view_helpers/action_view" require "bootstrap_pagination/bootstrap_renderer" +# TODO: Remove when will be fixed in will-paginate +require "bootstrap_pagination/fix_symbolize_update" + module BootstrapPagination # A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap. class Rails < WillPaginate::ActionView::LinkRenderer include BootstrapPagination::BootstrapRenderer + + if defined?(ActionController::Parameters) + include BootstrapPagination::FixSymbolizeUpdate + end end end diff --git a/lib/bootstrap_pagination/fix_symbolize_update.rb b/lib/bootstrap_pagination/fix_symbolize_update.rb new file mode 100644 index 0000000..1ebaba4 --- /dev/null +++ b/lib/bootstrap_pagination/fix_symbolize_update.rb @@ -0,0 +1,18 @@ +module BootstrapPagination + module FixSymbolizeUpdate + def symbolized_update(target, other) + other.each do |key, value| + key = key.to_sym + existing = target[key] + + is_params = lambda { |obj| obj.is_a?(Hash) || obj.is_a?(ActionController::Parameters) } + + if is_params.call(value) and (is_params.call(existing) or existing.nil?) + symbolized_update(existing || (target[key] = {}), value) + else + target[key] = value + end + end + end + end +end From 03fc9cc6fef311f2a4eba50ac40fe568c7bacafe Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Mon, 25 Jul 2016 15:19:01 +0300 Subject: [PATCH 2/2] Add defined? check --- lib/bootstrap_pagination/action_view.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap_pagination/action_view.rb b/lib/bootstrap_pagination/action_view.rb index 5bdde6e..491f679 100644 --- a/lib/bootstrap_pagination/action_view.rb +++ b/lib/bootstrap_pagination/action_view.rb @@ -2,7 +2,9 @@ require "bootstrap_pagination/bootstrap_renderer" # TODO: Remove when will be fixed in will-paginate -require "bootstrap_pagination/fix_symbolize_update" +if defined?(ActionController::Parameters) + require "bootstrap_pagination/fix_symbolize_update" +end module BootstrapPagination # A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap.