Redmine的插件仅出现在某些项目菜单中

时间:2012-07-30 13:34:48

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

我的Redmine(v2.0.3)工作了。它现在显示在每个项目的项目菜单中,但我无法弄清楚如何仅为所选项目激活它。例如。仅适用于将项目自定义字段设置为特定值的项目。我创建了自定义字段并找出了存储数据的位置。但是,如何告诉Redmine何时在项目菜单中显示插件?

我确实遇到过使用的可能性:如果要指定一个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()}

1 个答案:

答案 0 :(得分: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)}