Environment
- Mobility version: 1.3.2
- Mobility backend: jsonb
- Rails version: 8.1.1
- Ruby version: 3.4.6
- Database: PostgreSQL
Description
It seems there is an issue using normalizes with Mobility in ActiveRecord since Rails 8.1.
# config/initializers/mobility.rb
Mobility.configure do
plugins do
backend :jsonb
active_record
reader
writer
backend_reader
query
cache
column_fallback true
fallbacks true
presence
end
end
# app/models/content.rb
class Content < ApplicationRecord
extend Mobility
normalizes :data, with: -> { it.compact_blank }
translates :data, writer: false, column_fallback: false
end
Expected behavior
c = Content.new(data: { fr: "Non", en: "No", es: nil }) # => <Content id: nil, data: {"fr" => "ok", "en" => "nope"}>
c.save # => true
Actual behavior
c = Content.new(data: { fr: "Non", en: "No", es: nil }) # => <Content id: nil, data: {"fr" => "ok", "en" => "nope"}>
c.save # => undefined method 'compact_blank' for an instance of String (NoMethodError)
Error
normalizes method tries to execute a proc on a string (translated attribute) instead of the original column (Hash).
The same code works on Rails 8.0.
Do not hesitate to ask if you need complementary information.
Environment
Description
It seems there is an issue using
normalizeswithMobilityin ActiveRecord since Rails 8.1.Expected behavior
Actual behavior
Error
normalizesmethod tries to execute a proc on a string (translated attribute) instead of the original column (Hash).The same code works on Rails 8.0.
Do not hesitate to ask if you need complementary information.