Skip to content

Commit d98221a

Browse files
committed
Update method to return nothing if search bar is blank
I want to avoid returning the whole Member table if a user accidentally forgets to put in a search term. Although this can be managed with validation, I'm applying this at the lowest level for maximal protection Signed-off-by: jonathan.kerr <[email protected]>
1 parent cc279c5 commit d98221a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

app/models/member.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def recent_notes
119119
end
120120

121121
def self.find_members(name)
122-
where("CONCAT(name, ' ', surname) ILIKE ?", "%#{name}%")
122+
name.strip!
123+
name.eql?('') ? self.none : where("CONCAT(name, ' ', surname) ILIKE ?", "%#{name}%")
123124
end
124125

125126
private

0 commit comments

Comments
 (0)