From a3bcb1e06ac0d73999a5b74d70a234004e9f48b2 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 20 Aug 2019 12:05:04 +0800 Subject: [PATCH] Update personal_journals_controller.rb fix coding style --- .../personal_journals_controller.rb | 70 +++---------------- 1 file changed, 11 insertions(+), 59 deletions(-) diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 682acb4..8b3c826 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -3,17 +3,9 @@ class PersonalJournalsController < ApplicationController params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count journal_papers = JournalPaper.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) - page = begin - Page.where(page_id: params[:page_id]).first - rescue StandardError - nil - end + page = Page.where(page_id: params[:page_id]).first rescue nil if page.custom_string_field == 'table' - fields_to_show = begin - page.custom_array_field - rescue StandardError - [] - end + fields_to_show = page.custom_array_field rescue [] if fields_to_show.blank? fields_to_show = %w[ paper_title @@ -43,33 +35,17 @@ class PersonalJournalsController < ApplicationController when 'level_type' journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_levels.collect(&:title).join(', ').to_s, params[:keywords]) } when 'publication_date' - journal_papers_show = journal_papers_temp.select do |value| - search_all_words((begin - value.send('publication_date').strftime('%Y/%m/%d') - rescue StandardError - '' - end), params[:keywords]) - end + journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.send('publication_date').strftime('%Y/%m/%d') rescue ''), params[:keywords]) } when 'author_type' journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_paper_author_types.collect(&:title).join(', '), params[:keywords]) } when 'paper_type' - journal_papers_show = journal_papers_temp.select do |value| - search_all_words((begin - value.journal_paper_type.title - rescue StandardError - '' - end), params[:keywords]) - end + journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.journal_paper_type.title rescue ''), params[:keywords]) } when 'language' journal_papers_show = journal_papers_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } else journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } end - page_to_show = if params[:page_no].nil? - 1 - else - params[:page_no].to_i - end + page_to_show = params[:page_no].nil? ? 1 : params[:page_no].to_i journal_papers = journal_papers_show[(page_to_show - 1) * page_data_count...page_to_show * page_data_count] journal_papers_total_pages = (journal_papers_show.length / page_data_count.to_f).ceil else @@ -89,31 +65,15 @@ class PersonalJournalsController < ApplicationController when 'level_type' t << { 'value' => (!journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect(&:title).join(', ')})" : nil) } when 'publication_date' - t << { 'value' => (begin - journal_paper.send(fs).strftime('%Y/%m') - rescue StandardError - '' - end) } + t << { 'value' => (journal_paper.send(fs).strftime('%Y/%m') rescue '') } when 'author_type' - t << { 'value' => (begin - journal_paper.journal_paper_author_types.collect(&:title).join(', ') - rescue StandardError - '' - end) } + t << { 'value' => (journal_paper.journal_paper_author_types.collect(&:title).join(', ') rescue '') } when 'paper_type' - t << { 'value' => (begin - journal_paper.journal_paper_type.title - rescue StandardError - '' - end) } + t << { 'value' => (journal_paper.journal_paper_type.title rescue '') } when 'language' t << { 'value' => (!journal_paper.language.nil? ? t(journal_paper.language.to_s) : '') } else - t << { 'value' => (begin - journal_paper.send(fs) - rescue StandardError - '' - end) } + t << { 'value' => (journal_paper.send(fs) rescue '') } end end journal_paper_list << { 'jps' => t } @@ -182,11 +142,7 @@ class PersonalJournalsController < ApplicationController end def get_fields_for_index - @page = begin - Page.find(params[:page_id]) - rescue StandardError - nil - end + @page = Page.find(params[:page_id]) rescue nil @fields_to_show = %w[ year authors @@ -220,11 +176,7 @@ class PersonalJournalsController < ApplicationController end def save_index_fields - page = begin - Page.find(params[:page_id]) - rescue StandardError - nil - end + page = Page.find(params[:page_id]) rescue nil page.custom_array_field = params[:keys] page.save render json: { 'success' => true }.to_json