From 9cc12f7bc38bb2b2bf0d326ad4425b155555a7a9 Mon Sep 17 00:00:00 2001 From: hassaku Date: Wed, 7 Jan 2015 17:34:02 +0900 Subject: [PATCH] Show exceptions if updating note fails. --- app/controllers/fluentd/settings/notes_controller.rb | 8 ++------ app/models/fluentd/setting_archive/note.rb | 12 +++--------- config/locales/translation_en.yml | 1 - config/locales/translation_ja.yml | 1 - 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/app/controllers/fluentd/settings/notes_controller.rb b/app/controllers/fluentd/settings/notes_controller.rb index e1271d9..3846922 100644 --- a/app/controllers/fluentd/settings/notes_controller.rb +++ b/app/controllers/fluentd/settings/notes_controller.rb @@ -4,12 +4,8 @@ class Fluentd::Settings::NotesController < ApplicationController before_action :find_note, only: [:update] def update - if @note.update(params[:note][:content]) - flash[:success] = t('messages.note_updating_success') - else - flash[:error] = t('errors.messages.note_updating_failed') - end - redirect_to daemon_setting_path + @note.update!(params[:note][:content]) + redirect_to daemon_setting_path, flash: { success: t('messages.note_updating_success') } end private diff --git a/app/models/fluentd/setting_archive/note.rb b/app/models/fluentd/setting_archive/note.rb index 4aee755..94d9c0e 100644 --- a/app/models/fluentd/setting_archive/note.rb +++ b/app/models/fluentd/setting_archive/note.rb @@ -18,16 +18,10 @@ class Fluentd @file_path = file_path end - def update(content) - begin - File.open(@file_path, "w") do |f| - f.write content - end - rescue => ex - Rails.logger.error ex.message - return false + def update!(content) + File.open(@file_path, "w") do |f| + f.write content end - true end end end diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index 762155e..de25bf3 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -287,7 +287,6 @@ en: is_a_directory: is a directory. should be a file duplicated_conf: Configurations is duplicated out_forward_blank_server: server settings should be at least one - note_updating_failed: Updating the note is failed. See application logs. activemodel: &activemodel errors: diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index c28960c..6d572be 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -292,7 +292,6 @@ ja: is_a_directory: はディレクトリです。ファイルを指定してください duplicated_conf: 同じ内容の設定がすでに存在しています out_forward_blank_server: serverの設定がありません。 - note_updating_failed: メモの更新に失敗しました。ログを確認して下さい。 activemodel: &activemodel errors: