2017-02-20 125 views
0

我已更新會議插件。在此插件更新會議時,它不會更新會議歷史記錄。 像我改變主題會議更新主題,但不更新歷史問題。如何使用日記從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 

我已經做了以下事項>

我的模型類

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 

和控制器類

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 請幫我

+0

哪個版本的管理平臺? –

+0

它是最新版本。 我用我的環境更新了這個問題。 –

+0

和哪個會議插件? –

回答

1

你的日記對象(會議)應該有一個叫做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 
+0

是的,它的工作,但我給這樣的另一個錯誤。 未定義的方法'custom_field_values'爲#<會議:0x00000005761600> –

+0

http://prntscr.com/ebhaun –

+0

你應該看看「問題」模型,看看這些方法是如何實現的。然後,您只需調整並將其添加到您的自定義模型(會議)。 – Nanego

相關問題