プロジェクト

全般

プロフィール

ダウンロード (2 KB) 統計
| ブランチ: | タグ: | リビジョン:
02548925 TAKAHASHI,Toru
class GlossaryTermsController < ApplicationController

be33f1f6 Toru Takahashi
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
0e0aa071 Toru Takahashi
before_action :find_project_by_project_id, :authorize, except: [:preview]
before_action :find_attachments, only: [:preview]

02548925 TAKAHASHI,Toru
def index
88da1209 Toru Takahashi
@glossary_terms = GlossaryTerm.where(project_id: @project.id)
f78775ac Toru Takahashi
if not params[:index].nil?
@glossary_terms = @glossary_terms.search_by_name(params[:index])
elsif not params[:index_rubi].nil?
@glossary_terms = @glossary_terms.search_by_rubi(params[:index_rubi])
end
@grouping = params[:grouping] unless params[:grouping].nil?
02548925 TAKAHASHI,Toru
end
cffd7877 Toru Takahashi
a89d77b4 Toru Takahashi
def new
@term = GlossaryTerm.new
end
cffd7877 Toru Takahashi
c56501ba Toru Takahashi
def create
term = GlossaryTerm.new(glossary_term_params)
88da1209 Toru Takahashi
term.project = @project
ac1db68f Toru Takahashi
term.save_attachments params[:attachments]
c56501ba Toru Takahashi
if term.save
ac1db68f Toru Takahashi
render_attachment_warning_if_needed term
f0da3938 Toru Takahashi
redirect_to [@project, term], notice: l(:notice_successful_create)
c56501ba Toru Takahashi
end
end
fec83eef TAKAHASHI,Toru
def edit
end

def update
@term.attributes = glossary_term_params
ac1db68f Toru Takahashi
@term.save_attachments params[:attachments]
fec83eef TAKAHASHI,Toru
if @term.save
ac1db68f Toru Takahashi
render_attachment_warning_if_needed @term
f0da3938 Toru Takahashi
redirect_to [@project, @term], notice: l(:notice_successful_update)
fec83eef TAKAHASHI,Toru
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
end
be33f1f6 Toru Takahashi
def destroy
@term.destroy
9525306d Toru Takahashi
redirect_to project_glossary_terms_path(@project)
be33f1f6 Toru Takahashi
end
0e0aa071 Toru Takahashi
def preview
term = GlossaryTerm.find_by_id(params[:id])
if term
@attachments += term.attachments
@previewed = term
end
@text = params[:glossary_term][:description]
render partial: 'common/preview'
end
c56501ba Toru Takahashi
cffd7877 Toru Takahashi
# Find the term whose id is the :id parameter
def find_term_from_id
@term = GlossaryTerm.find(params[:id])
7a084fdb Toru Takahashi
rescue ActiveRecord::RecordNotFound
render_404
cffd7877 Toru Takahashi
end
c56501ba Toru Takahashi
private

def glossary_term_params
params.require(:glossary_term).permit(
c63ac320 Toru Takahashi
:name, :description, :category_id,
:name_en, :rubi, :abbr_whole, :datatype, :codename
c56501ba Toru Takahashi
)
end
02548925 TAKAHASHI,Toru
end