The plugin for Redmine will appear only in certain project menus

I got my Redmine (v2.0.3). Now it is displayed in the project menu of each project, but I can’t understand how to activate it only for selected projects. For instance. only for projects that have a custom project field set for a specific value. I created a custom field and figured out where the data is stored. But how can I tell Redmine when or not to show the plugin in the project menu?

It occurred to me to use: if you specify proc, but proc does not allow me to call the method of one of my created modules. For instance. I created a model called Param, and I want to call the Param.check_to_display method. But it shows an error message

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

My init.rb says:

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

How embarrassing, a simple mistake. I defined the check_to_display method as follows:

 def check_to_display 

obviously it should have been

 def self.check_to_display 

And for those interested in common code:

 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 

and don't forget, init.rb should look like this:

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

All Articles