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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:23:09+00:00 2026-05-26T11:23:09+00:00

I have a before_create callback that sets an error inside an object. class Animal

  • 0

I have a before_create callback that sets an error inside an object.

class Animal < ActiveRecord:base
   #omitted code
   def check_animal_has_non_poisoned_food
      if self.food.non_poisoned_food.nil?
        self.errors[:non_poisoned_food] = "Animal has non poisoned food"
        return false
      end
   end
end

for some reason, inside the controller, when I do an update attribute, although it fails validation

if animal.update_attributes(params[:animal])
  #ommitted
else
  #goes here
  ap animal.errors //empty
end

there is no error inside the animal.errors

  • 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-26T11:23:10+00:00Added an answer on May 26, 2026 at 11:23 am

    I don’t see anywhere in there that you’re adding an error. Typically that looks like this:

    self.errors.add("Animal has non poisoned food")
    

    Adding it to the attributes isn’t going to render it as an error even if you return false to break the create chain.

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

Sidebar

Related Questions

I have an ActiveRecord before_save method throwing an odd error: class MyThing < ActiveRecord::Base
I have a controller that makes HTTP GET requests using a custom class, which
I have a native C function (with JNI of course) that should callback a
I have a parent class called Exam and that has many instances of a
I have a block of code that will take a block of text like
I have a before_save defined as follows: def before_save self.token = generate_token end I
I want to check my database for records that I already have recorded before
I have the following before_filter : def find_current_membership respond_to do |wants| wants.html { @current_membership
I have a rails model User that has name , email and hash fields.
I have an ASP.NET app, very basic, but right now too much code to

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.