From 72ed467e7affec983c33d329c65c52fe00ab87b7 Mon Sep 17 00:00:00 2001 From: takayamaki / fusagiko <24884114+takayamaki@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:59:34 +0900 Subject: [PATCH] =?UTF-8?q?Settings::FavouriteTagsController=E3=82=92?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 過剰なbefore_actionを削除 --- .../settings/favourite_tags_controller.rb | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/app/controllers/settings/favourite_tags_controller.rb b/app/controllers/settings/favourite_tags_controller.rb index 96972d75d372f0..b552ad69953fa9 100644 --- a/app/controllers/settings/favourite_tags_controller.rb +++ b/app/controllers/settings/favourite_tags_controller.rb @@ -3,31 +3,42 @@ class Settings::FavouriteTagsController < Settings::BaseController layout 'admin' before_action :authenticate_user! - before_action :set_account - before_action :set_favourite_tags, only: [:index, :create] - before_action :set_favourite_tag, only: [:edit, :update, :destroy] def index + @favourite_tags = current_account.favourite_tags.with_order @favourite_tag = FavouriteTag.new(visibility: FavouriteTag.visibilities[:public]) end def edit - @favourite_tag + @favourite_tag = current_account.favourite_tags.find(params[:id]) end def create - name = create_params[:name].delete_prefix('#') - @favourite_tag = FavouriteTag.new(account: @account, name: name, order: create_params[:order], visibility: create_params[:visibility]) + @favourite_tag = FavouriteTag.new( + account: current_account, + name: create_params[:name].delete_prefix('#'), + order: create_params[:order], + visibility: create_params[:visibility] + ) + if @favourite_tag.save redirect_to settings_favourite_tags_path, notice: I18n.t('generic.changes_saved_msg') else + @favourite_tags = current_account.favourite_tags.with_order render :index end end def update - name = update_params[:name].delete_prefix('#') - if @favourite_tag.update(name: name, order: update_params[:order], visibility: update_params[:visibility]) + @favourite_tag = current_account.favourite_tags.find(params[:id]) + + @favourite_tag.update( + name: update_params[:name].delete_prefix('#'), + order: update_params[:order], + visibility: update_params[:visibility] + ) + + if @favourite_tag.save redirect_to settings_favourite_tags_path, notice: I18n.t('generic.changes_saved_msg') else render :edit @@ -35,7 +46,7 @@ def update end def destroy - @favourite_tag.destroy + current_account.favourite_tags.destroy(params[:id]) redirect_to settings_favourite_tags_path end @@ -49,15 +60,7 @@ def update_params params.require(:favourite_tag).permit(:name, :visibility, :order) end - def set_account - @account = current_user.account - end - - def set_favourite_tag - @favourite_tag = @account.favourite_tags.find(params[:id]) - end - - def set_favourite_tags - @favourite_tags = @account.favourite_tags.with_order + def current_account + current_user.account end end