开源项目 Redmine plugin 开发 patch model 不成功求解惑……

rc_plan · 2018年08月30日 · 最后由 rc_plan 回复于 2018年08月30日 · 6556 次阅读

想用插件的方法 TimeEntry 这个 model 中增加一个 validate,一直不成功,请哪位有经验的大神解解惑 patch 文件位置#{Rails.root}/plugins/time_entry_limit/lib/time_patch.rb

require 'time_entry'

module TimePatch
  def self.include(base)
    base.send(:include, InstanceMethods)

    base.class_eval do
      unloadable
      validates :issue_id, presence: true
    end
  end

  module InstanceMethods

  end
end

TimeEntry.send(:include, TimePatch)

plugin init 文件地址#{Rails.root}/plugins/time_entry_limit/init.rb

require 'redmine'


ActionDispatch::Callbacks.to_prepare do
  puts 'require ok====================' if require_dependency 'time_patch'
end

Redmine::Plugin.register :time_entry_limit do
  name 'Time Entry Limit plugin'
  author 'Author name'
  description 'This is a plugin for Redmine'
  version '0.0.1'
  url 'http://example.com/path/to/plugin'
  author_url 'http://example.com/about'

  settings :default => {'small' => 4}, :partial => 'settings/time_entry_limit_plugin'
end

代码如上

可是每次添加工时也就是往 time_entries 添加纪录时 issue_id 为空还是能添加成功

求助啊,要崩溃了……

自己好了,把 patch 文件删了,重新写了一遍就 ok 了,整个人都黑人问号了~~~~~

rc_plan 关闭了讨论。 08月31日 09:07
需要 登录 后方可回复, 如果你还没有账号请 注册新账号