redmine_glossary/app/controllers/glossary_terms_controller.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

class GlossaryTermsController < ApplicationController
2018-05-05 15:59:12 +02:00
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
2018-05-13 00:48:03 +02:00
before_action :find_project_from_id, only: [:index, :create]
def index
2018-05-13 00:48:03 +02:00
@glossary_terms = GlossaryTerm.where(project_id: @project.id)
end
2018-05-04 02:40:20 +02:00
2018-05-05 04:15:27 +02:00
def new
@term = GlossaryTerm.new
end
2018-05-04 02:40:20 +02:00
def create
term = GlossaryTerm.new(glossary_term_params)
2018-05-13 00:48:03 +02:00
term.project = @project
if term.save
redirect_to term, notice: l(:notice_successful_create)
end
end
2018-05-05 14:04:21 +02:00
def edit
end
def update
@term.attributes = glossary_term_params
if @term.save
redirect_to @term, notice: l(:notice_successful_update)
2018-05-05 14:04:21 +02:00
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
end
2018-05-05 15:59:12 +02:00
def destroy
2018-05-13 00:48:03 +02:00
project = @term.project
2018-05-05 15:59:12 +02:00
@term.destroy
2018-05-13 00:48:03 +02:00
redirect_to project.nil? ? home_path : project_glossary_terms_path(project)
2018-05-05 15:59:12 +02:00
end
2018-05-04 02:40:20 +02:00
# Find the term whose id is the :id parameter
def find_term_from_id
@term = GlossaryTerm.find(params[:id])
2018-05-04 03:08:14 +02:00
rescue ActiveRecord::RecordNotFound
render_404
2018-05-04 02:40:20 +02:00
end
2018-05-13 00:48:03 +02:00
# Find the project whose id is the :project_id parameter
def find_project_from_id
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
private
def glossary_term_params
params.require(:glossary_term).permit(
:name, :description, :category_id
)
end
end