From f78775ac43b4c0e431c6adf8669ff8feb87433f1 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Wed, 6 Jun 2018 01:21:17 +0900 Subject: [PATCH] [phase-11]add index by rubi --- app/controllers/glossary_terms_controller.rb | 8 ++++++-- app/models/glossary_term.rb | 4 ++++ app/views/glossary_terms/_sidebar.html.erb | 11 +++++++++++ config/locales/en.yml | 3 +++ config/locales/ja.yml | 13 +++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 12aa62b..6cac4f9 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -5,8 +5,12 @@ class GlossaryTermsController < ApplicationController def index @glossary_terms = GlossaryTerm.where(project_id: @project.id) - @glossary_terms = @glossary_terms.search_by_name(params[:index]) unless params[:index].nil? - @grouping = params[:grouping] + if not params[:index].nil? + @glossary_terms = @glossary_terms.search_by_name(params[:index]) + elsif not params[:index_rubi].nil? + @glossary_terms = @glossary_terms.search_by_rubi(params[:index_rubi]) + end + @grouping = params[:grouping] unless params[:grouping].nil? end def new diff --git a/app/models/glossary_term.rb b/app/models/glossary_term.rb index eee2c69..f044385 100644 --- a/app/models/glossary_term.rb +++ b/app/models/glossary_term.rb @@ -6,4 +6,8 @@ class GlossaryTerm < ActiveRecord::Base where 'name like ?', "#{sanitize_sql_like(keyword)}%" } + scope :search_by_rubi, -> (keyword) { + where 'rubi like ?', "#{sanitize_sql_like(keyword)}%" + } + end diff --git a/app/views/glossary_terms/_sidebar.html.erb b/app/views/glossary_terms/_sidebar.html.erb index 4232024..efe4cd4 100644 --- a/app/views/glossary_terms/_sidebar.html.erb +++ b/app/views/glossary_terms/_sidebar.html.erb @@ -35,4 +35,15 @@ <% end %> + + <% l(:index_rubi).each_line do |line| %> + + <% line.split(" ").each do |char| %> + + <% end %> + + <% end %> +
+ <%= link_to char, project_glossary_terms_path(index_rubi: char) %> +
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c4a8839..8eddff0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,6 +23,9 @@ en: S T U V W X Y Z + index_rubi: | + + permission_view_glossary: View glossary permission_manage_glossary: Manage glossary diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2034a95..f585da8 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -15,6 +15,19 @@ ja: label_grouping: グループ化 label_categorized: カテゴリで分類 + index_rubi: | + あ い う え お + か き く け こ + さ し す せ そ + た ち つ て と + な に ぬ ね の + は ひ ふ へ ほ + ま み む め も + や ゆ よ + ら り る れ ろ + わ を ん + + permission_view_glossary: 用語集の閲覧 permission_manage_glossary: 用語集の管理