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

rc_plan · August 30, 2018 · Last by rc_plan replied at August 30, 2018 · 6556 hits

想用插件的方法 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 closed this topic. 31 Aug 09:07
You need to Sign in before reply, if you don't have an account, please Sign up first.