Skip to content

Commit

Permalink
共通して使うメソッドを共通化する
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 28, 2024
1 parent f278ef3 commit 1163674
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
11 changes: 1 addition & 10 deletions app/controllers/talks/action_uncompleted_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class Talks::ActionUncompletedController < ApplicationController
include SearchUser
before_action :require_admin_login

def index
Expand All @@ -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
10 changes: 2 additions & 8 deletions app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
10 changes: 2 additions & 8 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions app/models/search_user.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1163674

Please sign in to comment.