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 7011845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:10:44+00:00 2026-05-27T22:10:44+00:00

Hi all I’m using active_resource and have next question. sometimes there is destroy validation

  • 0

Hi all I’m using active_resource and have next question.
sometimes there is destroy validation needed
Example

 def destroy
      if @user.destroy
        head :ok
      else
        respond_with(@user)
      end  
  end

user model can’t be deleted in few cases. If it wasn’t delete @user contains errors after validation before_delete
and responder serialize it like that
=> {\"errors\":{\"id\":[\"Cannot delete user with orders\"]}}

but active_resource don’t handle such response and fails with

ActiveResource::ResourceInvalid: Failed.  Response code = 422.  Response message = .

what is the best way to handle such situations?

  • 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-05-27T22:10:45+00:00Added an answer on May 27, 2026 at 10:10 pm

    I have never used ActiveResource so far, however I think this is the right way to implement a destroy method… or at least it’s the REST way.

    You said ActiveResource doesn’t handle such response, but actually that’s exactly the opposite. The ActiveResource::ResourceInvalid error is raised because of the 422 (Unprocessable Entity) response.

    More infos here : API ActiveResource

    Here is what the Resource errors part says :

    The following HTTP response codes will also result in these exceptions:

    …

    422 – ActiveResource::ResourceInvalid (rescued by save as validation errors)

    To sum up, these errors allow you to handle and behave accurately depending on the status code returned. For instance you don’t act the same way whether the response is a 503 (Service Unavailable) or a 422 (Unprocessable Entity). In first case you will probably said “Try again later” and in the second one “Cannot do that because of [message returned]”.

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

Sidebar

Related Questions

All I want is to make a simple user password login. I have put
all! A question to all the users of Mac OS X who have used
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
All throughout an application wherever error messages (or other user messages) are used I
All, I currently have two projects that are under SourceSafe that I am unable
All, I am running into an issue using JTextArea and JScrollPane. For some reason
All, I am trying to ensure that a file I have open with BufferedReader
All, I have the following array in array format. The JSON format is shown
All the guys probably will recommend that I read the follow previously question in
All, I have some script tags that are not working in Wordpress. If I

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.