Using Redmine Paginator in plugin

Added by Mikołaj Milej over 4 years ago

Hi

I'm trying to find out how to use Paginator class from redmine in plugin.
My current Redmine version: 2.3.0.
That plugin used to work with ruby 1.9.2 but with 2.0.0 not any more (probably some gems were updated too).

The code is on github - that file is included from here

It crashes with 500 in the browser and that backtrace in log

NameError (uninitialized constant Paginator):
  plugins/redmine_boards_watchers/inc/bw_boards_controller.rb:10:in `block (2 levels) in show_with_sp'
  actionpack (3.2.13) lib/action_controller/metal/mime_responds.rb:196:in `call'
  actionpack (3.2.13) lib/action_controller/metal/mime_responds.rb:196:in `respond_to'
  plugins/redmine_boards_watchers/inc/bw_boards_controller.rb:2:in `show_with_sp'
  actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.13) lib/active_support/callbacks.rb:491:in `_run__1362188719653511188__process_action__2247680673282264427__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `each'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
  rack-openid (1.3.1) lib/rack/openid.rb:98:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__1378427822725878925__call__1332278818434783494__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'
  passenger (4.0.0.rc6) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
  passenger (4.0.0.rc6) lib/phusion_passenger/request_handler/thread_handler.rb:135:in `accept_and_process_next_request'
  passenger (4.0.0.rc6) lib/phusion_passenger/request_handler/thread_handler.rb:106:in `main_loop'
  passenger (4.0.0.rc6) lib/phusion_passenger/request_handler.rb:458:in `block (4 levels) in start_threads'
  passenger (4.0.0.rc6) lib/phusion_passenger/utils/robust_interruption.rb:102:in `disable_interruptions'
  passenger (4.0.0.rc6) lib/phusion_passenger/request_handler.rb:453:in `block (3 levels) in start_threads'

Replies (4)

RE: Using Redmine Paginator in plugin - Added by Santiago Burgues over 4 years ago

Mikołaj, hi.

I have the same issue with that version of the pluggin... Did u manage to fix it?

Regards

RE: Using Redmine Paginator in plugin - Added by Mikołaj Milej over 4 years ago

Hi
Resolved Partially.
I commended out code (redmine_boards_watchers/lib/boards_watchers_patches.rb:74-85)in plugin that uses Paginator and everything seem to work. But it's workaround rather that finding out how to use Paginator.

RE: Using Redmine Paginator in plugin - Added by Zach Hamman over 4 years ago

It's in Redmine::Pagination::Paginator. I always had to ActionController::Pagination::Paginator in Redmine 1.x.

RE: Using Redmine Paginator in plugin - Added by T. Hauptman about 4 years ago

For others that find this, the following fixed it for me:

diff --git a/inc/bw_boards_controller.rb b/inc/bw_boards_controller.rb
index 1000807..0195213 100644
--- a/inc/bw_boards_controller.rb
+++ b/inc/bw_boards_controller.rb
@@ -7,19 +7,20 @@
                     'updated_on' => "#{Message.table_name}.updated_on" 

         @topic_count = @board.topics.count
-        @topic_pages = ActionController::Pagination::Paginator.new self, @topic_count, per_page_option, params['page
+        @topic_pages = Redmine::Pagination::Paginator.new @topic_count, per_page_option, params['page']
       # VVK
         order_sort = ["#{Message.table_name}.sticky_priority DESC", sort_clause].compact.join(', ')
         if Rails::VERSION::MAJOR >= 3
           @topics =  @board.topics.reorder(order_sort).all(:include => [:author, {:last_reply => :author}],
-                                        :limit  =>  @topic_pages.items_per_page,
-                                        :offset =>  @topic_pages.current.offset)
+                                        :limit  =>  @topic_pages.per_page,
+                                        :offset =>  @topic_pages.offset)

         else
           @topics =  @board.topics.find :all, :order => order_sort,
                                         :include => [:author, {:last_reply => :author}],
-                                        :limit  =>  @topic_pages.items_per_page,
-                                        :offset =>  @topic_pages.current.offset
+                                        :limit  =>  @topic_pages.per_page,
+                                        :offset =>  @topic_pages.offset
         end
       # VVK
         @message = Message.new(:board => @board)

(1-4/4)