Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:25:34+00:00 2026-06-18T05:25:34+00:00

I have a hierarchical Rails model. When it is validated, each instance of the

  • 0

I have a hierarchical Rails model. When it is validated, each instance of the model has an errors attribute that is an array of errors from validation. These errors need to be serialized into a JSON object that matches the hierarchy of the main model which generated the errors. Is there a way to leverage the ActiveModel::Serializer code so that I can use the associations already configured in the ActiveModel::Serializer subclasses so that I can traverse the hierarchical model and extract the errors into an object to send as JSON to the client?

Here is my hierarchical model:

class Submission < ActiveRecord::Base
  has_one :precipitation 
end

class Precipitation < ActiveRecord::Base
  has_one :precipitation_solid 
  belongs_to :submission
end

class PrecipitationSolid < ActiveRecord::Base
  has_many :precipitation_solid_samples
  belongs_to :precipitation
end

class PrecipitationSolidSample < ActiveRecord::Base
  belongs_to :precipitation_solid
end

I want to generate the following JSON when sample values are out of range

{"submission": {
  "precipitation": {
    "precipitation_solid": {
      "precipitation_solid_samples": [
        "accumulation out of range",
        "accumulation out of range"
      ]
    }
  }
}

Perhaps the ActiveModel::Serializer subclasses could do this directly. But if not, is there some way to inspect the associations defined in the serializers when I create the errors object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:25:36+00:00Added an answer on June 18, 2026 at 5:25 am

    The original motivation for this question was to find attributes for serialization of errors. Instead, after finding no resolution to this issue by looking at the GitHub issue noted by Deefour above, we switched to ActiveRecord::Reflection to find errors to search for and serialize errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hierarchical structure stored in a table. Each element has a pointer
I have a data structure that I'm looking to model and persist in rails.
I have some hierarchical data - each entry has an id and a (nullable)
I have a Hierarchical project that uses source code from a common system-directory, for
I have some hierarchical data (currently 6 levels). Each level has different attributes. I
I have an NSOutlineTableView that is displaying hierarchical HTML data, loaded from an HTML
I have Rails 3.1.2 app with a hierarchical relationship that looks like this: Categories
I have Hierarchical data. select lpad(' ', 4*(level-1))||NAME from from_sql where where_sql CONNECT BY
I have a highly structured hierarchical directory containing multiple files that need to be
I have data in a DB that have hierarchical relationship (could be represented as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.