From 11636747954d39f5596f92cdb75bd1520286026c Mon Sep 17 00:00:00 2001 From: yocchan-git Date: Thu, 28 Mar 2024 22:18:32 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=B1=E9=80=9A=E3=81=97=E3=81=A6=E4=BD=BF?= =?UTF-8?q?=E3=81=86=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=85=B1?= =?UTF-8?q?=E9=80=9A=E5=8C=96=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../talks/action_uncompleted_controller.rb | 11 +---------- app/controllers/talks_controller.rb | 10 ++-------- app/controllers/users_controller.rb | 10 ++-------- app/models/search_user.rb | 11 +++++++++++ 4 files changed, 16 insertions(+), 26 deletions(-) create mode 100644 app/models/search_user.rb diff --git a/app/controllers/talks/action_uncompleted_controller.rb b/app/controllers/talks/action_uncompleted_controller.rb index 3fc19ea5518..bfabaa3faf7 100644 --- a/app/controllers/talks/action_uncompleted_controller.rb +++ b/app/controllers/talks/action_uncompleted_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Talks::ActionUncompletedController < ApplicationController + include SearchUser before_action :require_admin_login def index @@ -19,14 +20,4 @@ def index @talks = @talks.page(params[:page]) end end - - private - - def validate_search_word(search_word) - if search_word.match?(/^[\w-]+$/) - search_word.strip if search_word.strip.length >= 3 - elsif search_word.strip.length >= 2 - search_word.strip - end - end end diff --git a/app/controllers/talks_controller.rb b/app/controllers/talks_controller.rb index 13d25ef93cb..cd40bfa0a36 100644 --- a/app/controllers/talks_controller.rb +++ b/app/controllers/talks_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class TalksController < ApplicationController + include SearchUser + before_action :require_admin_login, only: %i[index] before_action :set_talk, only: %i[show] before_action :set_user, only: %i[show] @@ -52,12 +54,4 @@ def set_members .where(id: User.admins.ids.push(@talk.user_id)) .order(:id) end - - def validate_search_word(search_word) - if search_word.match?(/^[\w-]+$/) - search_word.strip if search_word.strip.length >= 3 - elsif search_word.strip.length >= 2 - search_word.strip - end - end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e8fd4ae64b..c25d6bf4913 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class UsersController < ApplicationController + include SearchUser + skip_before_action :require_active_user_login, raise: false, only: %i[new create show] before_action :require_token, only: %i[new] if Rails.env.production? before_action :set_user, only: %w[show] @@ -194,12 +196,4 @@ def require_token redirect_to root_path, notice: 'アドバイザー・メンター・研修生登録にはTOKENが必要です。' end - - def validate_search_word(search_word) - if search_word.match?(/^[\w-]+$/) - search_word.strip if search_word.strip.length >= 3 - elsif search_word.strip.length >= 2 - search_word.strip - end - end end diff --git a/app/models/search_user.rb b/app/models/search_user.rb new file mode 100644 index 00000000000..7be513b19ef --- /dev/null +++ b/app/models/search_user.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module SearchUser + def validate_search_word(search_word) + if search_word.match?(/^[\w-]+$/) + search_word.strip if search_word.strip.length >= 3 + elsif search_word.strip.length >= 2 + search_word.strip + end + end +end