This project is archived and is in readonly mode.
ActiveResource validations
Reported by Matt Jankowski | November 23rd, 2010 @ 01:16 AM
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 {}>
Comments and changes to this ticket
-
Neeraj Singh November 23rd, 2010 @ 11:28 AM
- 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.
-
Matt Jankowski November 23rd, 2010 @ 01:44 PM
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?
-
Neeraj Singh November 23rd, 2010 @ 02:30 PM
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>