1

I create a plugin. I want to add an any settings for it into the projects settings. I want to create a new tab with my settings into the redmine project settings. I use the redmine version 3.1.0.devel. What can I do for that?

updated:

It's a code, which I created with help @General Failure

require 'projects_helper'

module ProjectsHelperPatch
  def self.included(base)
    base.send(:include, InstanceMethods)
    base.send(:include, ApplicationHelper)

    base.class_eval do
      unloadable

      alias_method_chain :project_settings_tabs, :sph
    end
  end

  module InstanceMethods
    def project_settings_tabs_with_sph

      abort('asdasd')

      tabs = project_settings_tabs_without_sph

      tabs.push({ :name => 'some_name',
                  :action => :some_action,
                  :partial => 'projects/settings/some_page',
                  :label => :label_some_label })
      return tabs
    end
  end
end

ProjectsHelper.send :include, ProjectsHelperPatch

init.rb:

require_relative '../../plugins/sph/app/patches/controllers/projects_helper_patch'

But its code don't works. Why?

jonua
  • 1,915
  • 3
  • 17
  • 27

1 Answers1

2

You can patch ProjectsHelper class and add alias_method_chain to project_settings_tabs method, see topic at Redmine forum.

In :partial => 'projects/settings/some_page' partial value is relative path to your view in plugin, also it must added to routes.rb.

If You have yet any questions, ask them in comments.


update:

My Redmine patching (no adding settings tab, just patching example):

require_dependency 'issues_controller'

module IssuesControllerPatch

  def self.included(base) # :nodoc:
    base.send(:include, InstanceMethods)
    base.send(:include, ApplicationHelper) # You can use helpers in patches

    base.class_eval do
      unloadable # Send unloadable so it will not be unloaded in development
      alias_method_chain :new, :patch
    end
  end

  module InstanceMethods

    def new_with_patch
        my_action # my code
        new_without_land_using # call original method
      end
    end

  end

end

IssuesController.send :include, IssuesControllerPatch

And init.rb row:

require 'patches/controllers/issues_controller_patch'
General Failure
  • 2,421
  • 4
  • 23
  • 49
  • I can't patch ProjectHelper with Dispatcher as it's describes in your topic, because Dispatcher was removed in Rails 3 (as far as I could understand) (I use rails v.4.2.4, I forgot to specify that, sorry). – jonua Oct 20 '15 at 05:27
  • Yes, but Redmine patching works same without dispatching too, now I add my code to answer – General Failure Oct 20 '15 at 05:33
  • I added the code, but it don't work. Where I made a bug? – jonua Oct 20 '15 at 07:20
  • Probably You must set permissions to new tab, look [help](http://www.redmine.org/boards/2/topics/11049). My code: ```project_module :my_plugin do permission :permission_name, {:my_controller => [:my_method]}, :public => true``` – General Failure Oct 20 '15 at 08:41
  • May be your path in ```require_relative```'s argument is wrong? Where is your projects_helper_patch.rb? If in ```plugin_folder/lib/patches```, ```require 'patches/projects_helper_patch'``` will be enough, no full path from application root needed. – General Failure Oct 20 '15 at 11:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92845/discussion-between-general-failure-and-kdjonua). – General Failure Oct 20 '15 at 11:25
  • Thank's alot! My mistake was that I do `require 'projects_helper'` instead of `require_dependenncy 'projects_helper'` – jonua Oct 21 '15 at 08:52