Skip to content

Commit

Permalink
Make use of confirmed scope
Browse files Browse the repository at this point in the history
Use confirmed scope for finding user by slug so there is no need
checking the user record directly
  • Loading branch information
kinsomicrote committed Oct 19, 2024
1 parent 99891bf commit 2958b9f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class ProfilesController < ApplicationController
before_action :disable_cache, only: :edit

def show
@user = User.find_by_slug!(params[:id])
return render_not_found unless @user.email_confirmed?
@user = User.confirmed.find_by_slug!(params[:id])
return render_not_found unless @user
@rubygems = @user.rubygems_downloaded.includes(%i[latest_version gem_download]).strict_loading
end

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class User < ApplicationRecord
scope :not_deleted, -> { kept }
scope :deleted, -> { with_discarded.discarded }
scope :with_deleted, -> { with_discarded }
scope :confirmed, -> { where(email_confirmed: true) }

has_many :ownerships, -> { confirmed }, dependent: :destroy, inverse_of: :user

Expand Down

0 comments on commit 2958b9f

Please sign in to comment.