patching application helper in redmine 2.3

Added by Moe H about 7 years ago

hey,

i've rewrote 'redmine_time_tracker' to work with the new unobtrusive javascript in rails 3 (and redmine >= 2.1). the plugin can be found here: https://github.com/mohikaner/redmine_time_tracker

my problem however is, that i'm patching the ApplicationHelper module:

require 'application_helper'

module TimeTrackers
  module Patches
    module ApplicationHelperPatch
      def self.included(base) # :nodoc:
        # sending instance methods to module
        base.send(:include, InstanceMethods)

        base.class_eval do
          unloadable

          # aliasing methods if needed
          # alias_method_chain :render_page_hierarchy, :watchers
        end
      end

      # Instance methods are here
      module InstanceMethods

        def time_tracker_for(user)
        TimeTracker.find(:first, :conditions => { :user_id => user.id })
        end

        def status_from_id(status_id)
        IssueStatus.find(:first, :conditions => { :id => status_id })
        end

        def statuses_list()
        IssueStatus.find(:all)
        end

        def to_status_options(statuses)
        options_from_collection_for_select(statuses, 'id', 'name')
        end

        def new_transition_from_options(transitions)
        statuses = []
        for status in statuses_list()
            if !transitions.has_key?(status.id.to_s)
            statuses << status
            end
        end
        to_status_options(statuses)
        end

        def new_transition_to_options()
        to_status_options(statuses_list())
        end

        def global_allowed_to?(user, action)
        return false if user.nil?

        projects = Project.find(:all)
        for p in projects
            if user.allowed_to?(action, p)
            return true
            end
        end

        return false
        end

      end
    end
  end
end

# now we should include this module in ApplicationHelper module
unless ApplicationHelper.included_modules.include? TimeTrackers::Patches::ApplicationHelperPatch
    ApplicationHelper.send(:include, TimeTrackers::Patches::ApplicationHelperPatch)
end

(this code looks like a mess, but i took it from the original plugin)

this worked pretty well in 2.1 and 2.2, but i've got an error in 2.3, that 'time_tracker_for' couldn't be found in the templates.
so could somebody point out to me, what has changed from 2.2 to 2.3? i've looked at the changelog from rails, and redmine, but couldn't find something, which would cause this.

Replies (5)

RE: patching application helper in redmine 2.3 - Added by Moe H about 7 years ago

further investigation shows, that application helper is patched (checked via console "ApplicationHelper.instance_methods.include?"), but i'm not able to use the methods in templates

RE: patching application helper in redmine 2.3 - Added by Jim McAleer almost 6 years ago

Any update on this? maybe a work around? I'm experiencing the same issue!

RE: patching application helper in redmine 2.3 - Added by Jim McAleer almost 6 years ago

I had the same issue and commented out the require 'redmine' in the init.rb and everything work just fine!!!

RE: patching application helper in redmine 2.3 - Added by yossi edri over 5 years ago

paste your method in the base.class_eval block like that.. it works for me

base.class_eval do
def method_name(issue)
//your code here
end
end

(1-5/5)