redmine_glossary/app/controllers/glossary_terms_controller.rb

49 lines
974 B
Ruby
Raw Normal View History

class GlossaryTermsController < ApplicationController
2018-05-05 14:04:21 +02:00
before_action :find_term_from_id, only: [:show, :edit, :update]
2018-05-04 02:40:20 +02:00
def index
2018-05-01 17:42:01 +02:00
@glossary_terms = GlossaryTerm.all
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)
if term.save
flash[:notice] = l(:notice_successful_create)
2018-05-05 14:04:21 +02:00
redirect_to term
end
end
2018-05-05 14:04:21 +02:00
def edit
end
def update
@term.attributes = glossary_term_params
if @term.save
flash[:notice] = l(:notice_successful_update)
redirect_to @term
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
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
private
def glossary_term_params
params.require(:glossary_term).permit(
:name, :description
)
end
end