From ac1db68faa2552cf0e340ef69275b9cca264d0f5 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sun, 10 Jun 2018 10:43:08 +0900 Subject: [PATCH] [phase-12]can be download attached file, new term with attachment --- app/controllers/glossary_terms_controller.rb | 6 ++++-- app/models/glossary_term.rb | 2 +- app/views/glossary_terms/edit.html.erb | 2 +- app/views/glossary_terms/new.html.erb | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) 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 @@

<%=l :label_glossary_term %> #<%= @term.id %>

-<%= labelled_form_for :glossary_term, @term, url: project_glossary_term_path do |f| %> +<%= labelled_form_for @term, url: project_glossary_term_path, html: {multipart: true} do |f| %> <%= render partial: 'glossary_terms/form', locals: {form: f} %> <%= f.submit l(:button_edit) %> <% end %> diff --git a/app/views/glossary_terms/new.html.erb b/app/views/glossary_terms/new.html.erb index d3863f9..918b4a8 100644 --- a/app/views/glossary_terms/new.html.erb +++ b/app/views/glossary_terms/new.html.erb @@ -1,7 +1,7 @@

<%=l :label_glossary_term_new %>

<%= labelled_form_for :glossary_term, @term, - url: project_glossary_terms_path do |f| %> + url: project_glossary_terms_path, html: {multipart: true} do |f| %> <%= render partial: 'glossary_terms/form', locals: {form: f} %> <%= f.submit l(:button_create) %> <% end %>