Get rid of single-use and slight awkward model scope

Really dont like that raw Arel.sql wrapping that is required.
This commit is contained in:
David Heinemeier Hansson
2025-04-05 13:17:42 +02:00
parent 61dfa5ecce
commit aefbac9c14
3 changed files with 6 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
module UsersHelper
def prepend_current_user_to(users_scope)
users_scope.to_a.prepend(Current.user).uniq
end
end
-1
View File
@@ -18,7 +18,6 @@ class User < ApplicationRecord
normalizes :email_address, with: ->(value) { value.strip.downcase }
scope :alphabetically, -> { order("lower(name)") }
scope :sorted_with_user_first, ->(user) { order(Arel.sql("users.id != ?, lower(name)", user.id)) }
def initials
name.to_s.scan(/\b\p{L}/).join.upcase
+1 -1
View File
@@ -12,7 +12,7 @@
</p>
<div class="flex align-center flex-wrap gap-half max-width txt-normal">
<%= render partial: "bubbles/watches/watcher", collection: @bubble.watchers.sorted_with_user_first(Current.user) %>
<%= render partial: "bubbles/watches/watcher", collection: prepend_current_user_to(@bubble.watchers.alphabetically) %>
</div>
</div>
<% end %>