4

我让我的 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()}
4

1 回答 1

2

多么尴尬,一个简单的错误。我将方法 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)}
于 2012-08-09T12:39:09.083 回答