Rails 7.1: Trouble with custom validation messages for nested attributes in forms
I'm experiencing an scenario where my custom validation messages for nested attributes aren't displayed when using Rails 7.1. I'm working with a `Project` model that has many `Tasks`, and I have a form that allows users to create a project along with its tasks. The validation for the `Task` model is set up to display custom messages, but they aren't appearing as expected. Here's how I've structured my models: ```ruby class Project < ApplicationRecord has_many :tasks, dependent: :destroy accepts_nested_attributes_for :tasks, allow_destroy: true validates :name, presence: { message: 'Project name want to be blank' } end class Task < ApplicationRecord belongs_to :project validates :description, presence: { message: 'Task description want to be blank' } end ``` In my form, I have: ```erb <%= form_with model: @project do |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.fields_for :tasks do |task_form| %> <%= task_form.label :description %> <%= task_form.text_field :description %> <%= task_form.error_messages %> <% end %> <%= f.submit 'Create Project' %> <% end %> ``` When I submit the form without providing a project name or task description, the project-level validation works fine and shows the appropriate behavior message. However, the task-level validation message is simply not displayed at all. I have tried explicitly calling `task_form.object.errors.full_messages`, but still nothing appears. I also checked that the `tasks` attributes are being correctly passed to the controller, and I can see the errors in the console logs. Hereβs the relevant part of the controller: ```ruby def create @project = Project.new(project_params) if @project.save redirect_to @project else render :new end end private def project_params params.require(:project).permit(:name, tasks_attributes: [:id, :description, :_destroy]) end ``` I'm wondering if there is something I've overlooked in the form helper or the way Rails handles nested attributes and errors in version 7.1. Any insights would be greatly appreciated! I'd really appreciate any guidance on this.