From 1378a95aa49bc786c72cb95ca5c9530671808f6b Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sun, 6 May 2018 23:39:57 +0900 Subject: [PATCH] [phase-5]add category field to term index/detail view, and edit form --- app/controllers/glossary_terms_controller.rb | 2 +- app/views/glossary_terms/_form.html.erb | 1 + app/views/glossary_terms/index.html.erb | 24 +++++++++++++------- app/views/glossary_terms/show.html.erb | 4 ++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index b60ac9a..b31f7eb 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -47,7 +47,7 @@ class GlossaryTermsController < ApplicationController def glossary_term_params params.require(:glossary_term).permit( - :name, :description + :name, :description, :category_id ) end end diff --git a/app/views/glossary_terms/_form.html.erb b/app/views/glossary_terms/_form.html.erb index e3da80d..b1e5e7f 100644 --- a/app/views/glossary_terms/_form.html.erb +++ b/app/views/glossary_terms/_form.html.erb @@ -1,4 +1,5 @@

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

+

<%= form.collection_select :category_id, GlossaryCategory.all, :id, :name, include_blank: true %>

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

diff --git a/app/views/glossary_terms/index.html.erb b/app/views/glossary_terms/index.html.erb index 69d96a2..8daead8 100644 --- a/app/views/glossary_terms/index.html.erb +++ b/app/views/glossary_terms/index.html.erb @@ -7,20 +7,28 @@ + + <% @glossary_terms.each do |term| %> - - - - + + + + + + <% end %>
# <%=l :field_name %><%=l :field_category %> <%=l :field_description %>
- <%= link_to term.name, term %> - - <%= term.description %> -
+ <%= term.id %> + + <%= link_to term.name, term %> + + <%= term.category.try!(:name) %> + + <%= term.description %> +
diff --git a/app/views/glossary_terms/show.html.erb b/app/views/glossary_terms/show.html.erb index 85a366b..e7a805a 100644 --- a/app/views/glossary_terms/show.html.erb +++ b/app/views/glossary_terms/show.html.erb @@ -9,6 +9,10 @@

<%= @term.name %>

+ + +
<%=l :field_category %><%= @term.category.try!(:name) %> +
<%=l :field_description %> <%= @term.description %>