【问题标题】:Plugin for Redmine to appear only in certain project menusRedmine 插件仅出现在某些项目菜单中
【发布时间】:2012-07-30 13:34:47
【问题描述】:

我的 Redmine (v2.0.3) 工作正常。它现在显示在每个项目的项目菜单中,但我不知道如何只为选定的项目激活它。例如。仅适用于项目自定义字段设置为特定值的项目。我创建了自定义字段并确定了数据的存储位置。但是我如何告诉 Redmine 何时在项目菜单中显示插件?

我确实遇到了使用 :if 来指定 proc 的可能性,但 proc 不允许我调用我的插件创建模型之一的方法。 例如。我创建了一个名为 Param 的模型,我想调用方法 Param.check_to_display。 但显示错误信息

ActionView::Template::Error (undefined method 'check_to_display' for Param(....):Class)

我的 init.rb 说:

menu :project_menu, :info, {:controller=>'info', :action=>'index'}, :caption=>'Ticker', :after=>:activity, :param=>:project_id, :if=>Proc.new{||Param.check_to_display()}

【问题讨论】:

    标签: ruby-on-rails redmine redmine-plugins


    【解决方案1】:

    多么尴尬,一个简单的错误。我将方法 check_to_display 定义如下:

    def check_to_display
    

    应该是这样的

    def self.check_to_display
    

    对于那些对总代码感兴趣的人:

    class Param < ActiveRecord::Base
      unloadable
    
      def self.check_to_display(p)
        cf = CustomField.where("type='ProjectCustomField' and name='THE_FLAG'").first
        return false if cf.nil?
        return false if p.nil?
        cv = CustomValue.where("customized_type='Project' and customized_id=? and custom_field_id=?",p.id,cf.id).first
        return false if cv.nil?
        return false if cv.value.nil?
        cv.value.strip!
        return cv.value != ""
      end
    end
    

    别忘了,init.rb 应该如下所示:

    menu :project_menu, :info, {:controller=>'info', :action=>'index'}, :caption=>'Ticker', :after=>:activity, :param=>:project_id, :if=>Proc.new{|p|Param.check_to_display(p)}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      相关资源
      最近更新 更多