This project is archived and is in readonly mode.
ActiveResource instance.valid? has no validate callbacks
Reported by Hugh | July 23rd, 2008 @ 05:09 AM | in 2.x
Taking an example from the docs:
class Person < ActiveResource::Base
self.site = "http://www.localhost.com:3000/"
protected
def validate
errors.add("phone_number", "has invalid format") unless phone_number =~ /[0-9]*/
end
end
As you can see valid? does not trigger any callbacks like ActiveRecord:
person = Person.new("first_name" => "Jim", "phone_number" => "I will not tell you.")
person.valid? # => true
person.errors.add("phone_number", "has invalid format") unless :phone_number =~ /[0-9]*/
person.valid? # => false
Comments and changes to this ticket
-
Smilinguy July 27th, 2008 @ 06:58 AM
I'm also having the same issue where my validate method is not called on valid?.
In fact, my validate isn't even called on save! unless there have been attributes modified.
In my case, these objects were created before I added new validation rules. If I try and save! them now, I would expect them to fail validation but they don't.
-
Paul Horsfall July 30th, 2008 @ 01:06 PM
I think that all validation in Active Resource is done by the remote service. There's "an old patch on Trac":
http://dev.rubyonrails.org/ticke... to fix the documentation which I was thinking about reviving to clear things up. Should I?
-
Tim Morton August 18th, 2008 @ 05:04 PM
I would vote in favor of fixing the code to match the docs, not vice versa. Local validations are useful.
See http://www.akitaonrails.com/2008... for a start.
-
josh November 22nd, 2008 @ 07:00 PM
- State changed from new to wontfix
ARes doesn't have validations or callbacks yet. I'm assuming this is coming when we switch it over to ActiveModel.
-
Thijs December 2nd, 2008 @ 12:51 PM
The documentation still says you can add a def validate to validate locally. Shouldn't this be removed untill it's actually working?
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>