2017-02-20 5 views
0

У меня есть обновление плагина встречи. в этом плагине при обновлении собрания он не обновляет историю собрания. как я изменяю тему для встречи с ней, обновляю тему, но не обновляю историю, как проблему.Как добавить элемент истории из плагина Redmine с помощью журнала

моя конфигурация 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 

Я сделал following->

для моей модели класса

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

Какого Redmine версия? –

+0

его последняя версия. Я обновляю вопрос с помощью своей среды. –

+0

А какие плагины для встреч? –

ответ

1

Вашей журналируемой объект (Meeting) должен иметь метод, называемый 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

Да, это работает, но я даю еще одну ошибку. undefined method 'custom_field_values ​​'для #

+0

http://prntscr.com/ebhaun –

+0

Вы должны посмотреть на модель« Проблема »и посмотреть, как эти методы реализованы. Тогда вам просто нужно адаптироваться и добавить их в свою собственную модель (собрание). – Nanego

Смежные вопросы