diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 8f96902..cf7b32a 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -20,7 +20,9 @@ class GlossaryTermsController < ApplicationController def create term = GlossaryTerm.new(glossary_term_params) term.project = @project + term.save_attachments params[:attachments] if term.save + render_attachment_warning_if_needed term redirect_to [@project, term], notice: l(:notice_successful_create) end end @@ -30,9 +32,9 @@ class GlossaryTermsController < ApplicationController def update @term.attributes = glossary_term_params - @term.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@term) + @term.save_attachments params[:attachments] if @term.save + render_attachment_warning_if_needed @term redirect_to [@project, @term], notice: l(:notice_successful_update) end rescue ActiveRecord::StaleObjectError diff --git a/app/models/glossary_term.rb b/app/models/glossary_term.rb index d0d4a25..88ea9b5 100644 --- a/app/models/glossary_term.rb +++ b/app/models/glossary_term.rb @@ -3,7 +3,7 @@ class GlossaryTerm < ActiveRecord::Base belongs_to :project # class method from Redmine::Acts::Attachable::ClassMethods - acts_as_attachable + acts_as_attachable view_permission: :view_glossary, edit_permission: :manage_glossary, delete_permission: :manage_glossary scope :search_by_name, -> (keyword) { where 'name like ?', "#{sanitize_sql_like(keyword)}%" diff --git a/app/views/glossary_terms/edit.html.erb b/app/views/glossary_terms/edit.html.erb index 6c45c2a..fdbfbd1 100644 --- a/app/views/glossary_terms/edit.html.erb +++ b/app/views/glossary_terms/edit.html.erb @@ -1,6 +1,6 @@