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.

ActiveResource validations

#6041

I expected to have invalid records when I added to errors locally, regardless of contacting the server - is that inaccurate?

    ruby-1.8.7-p302 > class Widget < ActiveResource::Base
    ruby-1.8.7-p302 ?>  end
     => nil 
    ruby-1.8.7-p302 > 
    ruby-1.8.7-p302 >   widget = Widget.new
     => #<Widget:0x10522dd40 @prefix_options={}, @attributes={}> 
    ruby-1.8.7-p302 > widget.errors
     => #<OrderedHash {}> 
    ruby-1.8.7-p302 > widget.valid?
     => true 
    ruby-1.8.7-p302 > widget.errors
     => #<OrderedHash {}> 
    ruby-1.8.7-p302 > widget.errors.add :base, 'invalid'
     => ["invalid"] 
    ruby-1.8.7-p302 > widget.errors
     => #<OrderedHash {:base=>["invalid"]}> 
    ruby-1.8.7-p302 > widget.valid?
     => true 
    ruby-1.8.7-p302 > widget.errors
     => #<OrderedHash {}>

Reported by Matt Jankowski · November 23rd, 2010 @ 01:16 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh
    • State changed from new to resolved
    • Importance changed from to Low

    ActiveRecord and ActiveResource clears all the errors when .valid? is called. Right now I am not able to locate the code but I know that's what happens.

    November 23rd, 2010 @ 11:28 AM

  2. Matt Jankowski
    Matt Jankowski

    ActiveResource calls super - https://github.com/rails/rails/blob/master/activeresource/lib/activ...

    ActiveModel does the clear - https://github.com/rails/rails/blob/master/activemodel/lib/active_m...

    So I guess my issue isn't with how or where that's happening, rather - why does it work that way, and is there a way to do what I wanted to do?

    November 23rd, 2010 @ 01:44 PM

  3. Neeraj Singh
    Neeraj Singh

    I guess one reason I need the current behavior is to be able to do this.

    c = Car.new
    c.valid? #=> false 
    c.name = 'Honda'
    c.valid? #=> true
    

    If the errors are not cleared then manually I will have to clear it.

    November 23rd, 2010 @ 02:30 PM