如何使用日志从 Redmine 插件添加历史记录项

How to add history item from Redmine plugin using journal

我已经更新了会议插件。在此插件中,更新会议时不会更新会议历史记录。 就像我改变主题来满足它更新主题但不更新历史一样的问题。

我的redmine配置如下

Environment:
  Redmine version                3.3.1.stable
  Ruby version                   2.1.5-p273 (2014-11-13) [x86_64-linux]
  Rails version                  4.2.7.1
  Environment                    development
  Database adapter               Mysql2

我已经完成了->

我的模型 class

 def init_journal(user, notes = "")
  @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes, :notify => false)

    if new_record?
      @current_journal.notify = false
    else
      @attributes_before_change = attributes.dup
    end
    @current_journal
  end

  def last_journal_id
    if new_record?
      nil
    else
      journals.maximum(:id)
    end
  end

  # Returns a scope for journals that have an id greater than journal_id
  def journals_after(journal_id)
    scope = journals.reorder("#{Journal.table_name}.id ASC")
    if journal_id.present?
      scope = scope.where("#{Journal.table_name}.id > ?", journal_id.to_i)
    end
    scope
  end

  def create_journal
    if @current_journal
      # attributes changes
      if @attributes_before_change
        (Meeting.column_names - %w(id created_at updated_at)).each {|c|
          before = @attributes_before_change[c]
          after = send(c)
          next if before == after || (before.blank? && after.blank?)
          @current_journal.details << JournalDetail.new(:property => 'attr',
                                                        :prop_key => c,
                                                        :old_value => before,
                                                        :value => after)
        }
      end
      @current_journal.save
      # reset current journal
      init_journal @current_journal.user, @current_journal.notes
    end
  end

和控制器 class

def update_meeting_from_params
    @edit_allowed = User.current.allowed_to?(:edit_meetings, @project)
    @time_entry = TimeEntry.new(:meeting => @meeting, :project => @meeting.project)
    @time_entry.attributes = params[:time_entry]

    @meeting.init_journal(User.current)

    meeting_attributes = params[:meeting]
    @meeting.safe_attributes = meeting_attributes
  end

我收到以下错误。 http://prntscr.com/eb257g 请帮助我

您的日记化 object(会议)应该有一个名为 journalized_attribute_names

的方法

尝试将其添加到您的模型中 (meeting.rb):

# Returns the names of attributes that are journalized when updating the meeting
def journalized_attribute_names
  names = Meeting.column_names - %w(id created_on updated_on)
  names
end