From a89d77b4f6b32e9487c1349e44923fcd190de413 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 5 May 2018 11:15:27 +0900 Subject: [PATCH] [phase-4]add new form --- app/controllers/glossary_terms_controller.rb | 6 +++--- app/views/glossary_terms/_form.html.erb | 4 ++++ app/views/glossary_terms/new.html.erb | 7 +++++++ config/locales/en.yml | 1 + config/locales/ja.yml | 2 +- config/routes.rb | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 app/views/glossary_terms/_form.html.erb create mode 100644 app/views/glossary_terms/new.html.erb diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index f2f5767..5cb2a10 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -6,9 +6,9 @@ class GlossaryTermsController < ApplicationController @glossary_terms = GlossaryTerm.all end -# def show - -# end + def new + @term = GlossaryTerm.new + end # Find the term whose id is the :id parameter def find_term_from_id diff --git a/app/views/glossary_terms/_form.html.erb b/app/views/glossary_terms/_form.html.erb new file mode 100644 index 0000000..e3da80d --- /dev/null +++ b/app/views/glossary_terms/_form.html.erb @@ -0,0 +1,4 @@ +
+

<%= form.text_field :name, size: 80, required: true %>

+

<%= form.text_area :description, size: "80x10", required: false %>

+
diff --git a/app/views/glossary_terms/new.html.erb b/app/views/glossary_terms/new.html.erb new file mode 100644 index 0000000..e7f59c1 --- /dev/null +++ b/app/views/glossary_terms/new.html.erb @@ -0,0 +1,7 @@ +

<%=l :label_glossary_term_new %>

+ +<%= labelled_form_for :glossary_term, @term, + url: glossary_terms_path do |f| %> + <%= render partial: 'glossary_terms/form', locals: {form: f} %> + <%= f.submit l(:button_create) %> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1c53864..c403bbd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,3 +2,4 @@ en: label_glossary_terms: "Glossary terms" label_glossary_term: "Glossary term" + label_glossary_term_new: "New glossary term" \ No newline at end of file diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 14300a3..e3dcb96 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1,4 +1,4 @@ ja: label_glossary_terms: "用語集" label_glossary_term: "用語" - \ No newline at end of file + label_glossary_term_new: "用語の作成" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 396cc9a..d003913 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,5 @@ # See: http://guides.rubyonrails.org/routing.html Rails.application.routes.draw do - resources :glossary_terms, only: [:index, :show] + resources :glossary_terms, only: [:index, :show, :new, :create] end