【发布时间】:2020-04-07 07:26:59
【问题描述】:
我已经研究这个术语很多小时了,但我发现了一些有用的东西。 希望您能帮助我们构建这个 redmine 插件,或者提供一些研究链接来帮助我们找到正确的密钥。
我们想要构建什么
问题是我们想在 redmine 中更新一个自定义字段(我们将其命名为“Target_CF”),每当创建或更新另一个自定义字段时。 我们正在寻找增加 Target_CF 的可能值,因此我们可以选择所有自定义字段的名称。 当然,我们希望在不直接编辑 Redmine 的 Core 的情况下实现这一点,因此我们认为开发插件是最好的方法。
我们的插件还创建和配置了一个新的自定义字段(上面提到的那个),但我不会考虑这个,因为我认为它与此无关。
我们现在的位置
我们已经确定了一些可能对我们有用的钩子,如下所示:
- :controller_custom_fields_new_after_save
- :controller_custom_fields_edit_after_save
到目前为止,我们有以下目录/文件结构:
plugins/
custom_plugin/
init.rb
lib/
hooks.rb
我们写的代码
init.rb
require_dependency 'hooks'
Redmine::Plugin.register :custom_plugin do
name 'custom_plugin'
author 'author name'
description 'description text'
version '1.0.0'
end
hooks.rb
class Hooks < Redmine::Hook::ViewListener
def controller_custom_fields_edit_after_save(context={ })
@target_custom_field_name = "Target_CF"
CustomField.find_by_name(@target_custom_field_name).possible_values.push(context[:custom_field].name)
end
end
这段代码的结果是无。我的意思是,没有错误,没有更新,什么都没有。编辑/创建另一个自定义字段后,我们的可能值没有变化。我们确信有一些我们不知道的东西,一些概念或工作流程,因此我们做得很糟糕。 请帮助我们了解我们缺少什么。
之前我们已经成功开发了另一个覆盖某些视图的插件。所以我们在视图相关的插件方面有一点技能,但在控制器方面却是零经验。
我们正在使用 Bitnami 的 Redmine 3.2.0 堆栈和一个 mysql 数据库。
【问题讨论】:
标签: plugins controller hook redmine custom-fields