-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
This model uses ActiveRecord::Base.normalizes feature it's from rails version 7.1.
https://api.rubyonrails.org/classes/ActiveRecord/Normalization/ClassMethods.html#method-i-normalizes
class Book < ApplicationRecord
# Convert full-width characters to half-width
normalizes :title, with: ->(value){
value.tr('A-Za-z', 'A-Za-z')
}
search_scope :search do
attributes :title
end
endBook.create(title: 'ABCDE') # full-width
=> #<Book id: 1, title: "ABCDE"> # converted to half-widthBook.search('ABC').to_sql
=> "SELECT * FROM books WHERE title ILIKE '%ABC%'" # expected
=> "SELECT * FROM books WHERE title ILIKE '%ABC%'" # actualI tried to create a pull request. But it was too difficult for me. 😢
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels