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