我使用的是Redmine 3.4.6,当问题状态更改为特定状态时,我需要让它添加一个注释。我发现它可以通过保存钩子后的控制器问题编辑来实现,但我找不到任何好的例子来写控制器钩子。我是Ruby和编码的初学者,所以我请某人解释我必须做什么才能让它工作。发布
我的代码:
module RedmineAutocomments
module Hooks
class RedmineAutocommentsHook < Redmine::Hook::ViewListener
def controller_issues_edit_after_save(context={})
issue = context[:issue]
trackers = ["Tracker1", "Tracker2", "Tracker3"]
if trackers.include? @issue.tracker
if @issue.status == "Ready for handout"
@comment = Comment.new
@comment = 'Some comment need to be added'
@news.comments << @comment
end
end
end
end
end
end
一切都不是很困难:
module RedmineAutocomments
module Hooks
class RedmineAutocommentsHook < Redmine::Hook::ViewListener
def controller_issues_edit_after_save(context={})
@issue = context[:issue]
case @issue.project.id
when 9
case @issue.tracker.id
when 13, 14, 20
case @issue.status.id
when 26
@issue.notes = MESSAGE
@issue.save
end
end
end
end
end
end
end