プロジェクト

全般

プロフィール

« | » 

リビジョン ac1db68f

高徹 高橋 徹 さんが約6年前に追加

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

差分を表示:

app/controllers/glossary_terms_controller.rb
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
......
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
app/models/glossary_term.rb
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)}%"
app/views/glossary_terms/edit.html.erb
<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} %>
<%= f.submit l(:button_edit) %>
<% end %>
app/views/glossary_terms/new.html.erb
<h2><%=l :label_glossary_term_new %></h2>
<%= 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 %>

他の形式にエクスポート: Unified diff