Well.... it works for SimpleRecord attributes but if I have an
attr_accessor it gives bogus errors
class Foo < SimpleRecord::Base
has_strings :password
attr_accessor :new_password
# For this example new_passwords must be formated like emails
validates_format_of :new_password, :with => /^[-a-z0-9_+\.]+\@([-a-
z0-9]+\.)+[a-z0-9]{2,4}$/i
# Stuff for encrypting and setting password...
end
bar = Foo.new
bar.new_password =
te...@test.com
bar.valid? #=> false
bar.errors #=> {:new_password=>["is invalid"]}
Thanks,
Josh
On Mar 15, 4:46 pm, Travis Reeder <
tree...@gmail.com> wrote:
> I know this is old but if u get a chance to try it again, there were some
> big updates with regards to rails 3 / activemodel validations recently.
> On Jan 7, 2011 11:59 AM, "joshmckin" <
joshmc...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Using SimpleRecord in a Rails3 project. Rails3 validates_format_of
> > works as expected for NEW records. However, on existing records
> > validates_format_of incorrectly fails validation even if the existing
> > value is valid. It likely has to do with values for attributes being
> > stored in arrays on lookups.
>
> > class User < SimpleRecord::Base
> > has_string :email
>
> > validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+
> > [a-z0-9]{2,4}$/i, :allow_blank => true
> > end
>
> > u = User.new
> > u.email = "
g...@email.com"
> > u.valid? # => true
> > u.save
>
> > found = User.find(
u.id)
> > found.email # => "
g...@email.com
> > found.valid? # => false
> > found.errors # => {:email_address=>["is an invalid format."]}
>
> > found.email = "
newg...@email.com"