How to handle custom scenarios messages in a Rails 7 service object with ActiveModel validations?
I'm updating my dependencies and I'm currently working on a Rails 7 application where I'm trying to implement a service object that uses `ActiveModel::Validations` to validate some business logic before saving data to the database... However, I'm working with issues with custom behavior messages not appearing as expected. Here's a snippet of my service object: ```ruby class UserRegistrationService include ActiveModel::Model attr_accessor :email, :password validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP, message: 'must be a valid email address' } validates :password, presence: true, length: { minimum: 6, message: 'must be at least 6 characters long' } def save return false unless valid? # Simulating user creation logic User.create(email: email, password: password) end end ``` When I create an instance of `UserRegistrationService` and call `save`, I'm checking for errors, but the custom messages arenβt showing up in the way I expect: ```ruby service = UserRegistrationService.new(email: '', password: '123') if !service.save puts service.errors.full_messages end ``` I expected to see messages like 'must be a valid email address' and 'must be at least 6 characters long', but instead, I'm only getting generic behavior messages about presence and length. I've double-checked that the validations are defined correctly, and I've ensured I'm calling `valid?` before attempting to save. I'm not sure if I'm missing a configuration or if there's a specific way to handle custom behavior messages in service objects. Could someone guide me on how to properly set up these custom messages so they are displayed when validation fails? My team is using Ruby for this microservice. Hoping someone can shed some light on this. The project is a desktop app built with Ruby. I recently upgraded to Ruby stable. This is part of a larger mobile app I'm building.