[phase-12]can be download attached file, new term with attachment

This commit is contained in:
Toru Takahashi 2018-06-10 10:43:08 +09:00 committed by TAKAHASHI,Toru
parent fe492e0488
commit ac1db68faa
4 changed files with 7 additions and 5 deletions

View File

@ -20,7 +20,9 @@ class GlossaryTermsController < ApplicationController
def create def create
term = GlossaryTerm.new(glossary_term_params) term = GlossaryTerm.new(glossary_term_params)
term.project = @project term.project = @project
term.save_attachments params[:attachments]
if term.save if term.save
render_attachment_warning_if_needed term
redirect_to [@project, term], notice: l(:notice_successful_create) redirect_to [@project, term], notice: l(:notice_successful_create)
end end
end end
@ -30,9 +32,9 @@ class GlossaryTermsController < ApplicationController
def update def update
@term.attributes = glossary_term_params @term.attributes = glossary_term_params
@term.save_attachments(params[:attachments]) @term.save_attachments params[:attachments]
render_attachment_warning_if_needed(@term)
if @term.save if @term.save
render_attachment_warning_if_needed @term
redirect_to [@project, @term], notice: l(:notice_successful_update) redirect_to [@project, @term], notice: l(:notice_successful_update)
end end
rescue ActiveRecord::StaleObjectError rescue ActiveRecord::StaleObjectError

View File

@ -3,7 +3,7 @@ class GlossaryTerm < ActiveRecord::Base
belongs_to :project belongs_to :project
# class method from Redmine::Acts::Attachable::ClassMethods # 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) { scope :search_by_name, -> (keyword) {
where 'name like ?', "#{sanitize_sql_like(keyword)}%" where 'name like ?', "#{sanitize_sql_like(keyword)}%"

View File

@ -1,6 +1,6 @@
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2> <h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
<%= 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} %> <%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_edit) %> <%= f.submit l(:button_edit) %>
<% end %> <% end %>

View File

@ -1,7 +1,7 @@
<h2><%=l :label_glossary_term_new %></h2> <h2><%=l :label_glossary_term_new %></h2>
<%= labelled_form_for :glossary_term, @term, <%= 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} %> <%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_create) %> <%= f.submit l(:button_create) %>
<% end %> <% end %>