From c56501baa6684cf36528c24e9bb4eda8f075e14d Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 5 May 2018 16:53:58 +0900 Subject: [PATCH] [phase-4]implemented controller create method --- app/controllers/glossary_terms_controller.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 5cb2a10..c0e6725 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -10,10 +10,26 @@ class GlossaryTermsController < ApplicationController @term = GlossaryTerm.new end + def create + term = GlossaryTerm.new(glossary_term_params) + if term.save + flash[:notice] = l(:notice_successful_create) + redirect_to glossary_term_path(term.id) + end + end + # Find the term whose id is the :id parameter def find_term_from_id @term = GlossaryTerm.find(params[:id]) rescue ActiveRecord::RecordNotFound render_404 end + + private + + def glossary_term_params + params.require(:glossary_term).permit( + :name, :description + ) + end end