Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

deserialize error messages directly from error hash instead of an array of messages

#6014

Currently errors are interpreted and received in the following format:

    <?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error></errors>
    {"errors":["Age can't be blank","Name can't be blank","Name must start with a letter","Person quota full for today."]}

With the attached patch the following will be correctly interpreted:

    <?xml version="1.0" encoding="UTF-8"?><errors><age type="array"><age>can't be blank</age></age><name type="array"><name>can't be blank</name><name>must start with a letter</name></name><base type="array"><base>Person quota full for today.</base></base></errors>
    {"errors":{"age":"can't be blank","name":["can't be blank","must start with a letter"],"base":"Person quota full for today."}}

We feel that this is a more flexible and direct solution; the code to interpret this is more readable and shorter and it allows for such things as translating error messages in the backend and being able to still associate them with the correct attribute in the frontend.

One thing that needs fixing before applying this is #5615 Support multiple errors per attribute in ActiveModel Errors JSON serialization, which will then allow to have multiple error messages on one attribute.

Reported by Frank Prößdorf · November 19th, 2010 @ 03:44 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Thilo Utke
    Thilo Utke

    removed whitespace from diff.

    November 19th, 2010 @ 04:39 PM

  2. Sebastian Cohnen
  3. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 20th, 2011 @ 12:00 AM

  4. rails
    rails
    • State changed from open to stale

    February 20th, 2011 @ 12:00 AM