diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 9108ba9..965aaeb 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -163,7 +163,14 @@ end @template.description = params["template-desc"] if @template.update_attributes(params[:template]) - if @template.published + if @template.published? + # unpublish older versions + Template.where("dmptemplate_id = ? AND published = ? AND version < ?", + @template.dmptemplate_id, true, @template.version).each do |t| + t.published = false + t.save + end + # create a new template version if this template became published new_version = Template.deep_copy(@template) new_version.version = @template.version + 1