Unfortunately Desert doesn't help us with overriding filters, validations
and associations. That means you can't just re-declare a validation in your
overriding model and expect it to work. Instead, you have to do an ugly
hack, something like:

class User < ActiveRecord::Base
  after_validation :fix_errors

  def fix_errors

    self.errors.remove(:login) #remove all errors on login

    unless self.login ~= /^[\s\.A-Za-z0-9_-]+$/ #(replace with whatever
regex you want)
      errors.add(:login, "is invalid")
    end
  end

end

And also add an initialize in config/ar_remove_error.rb:

module ActiveRecord

  class Errors
    #removes all errors on the given attribute
    def remove(attribute)
      @errors.delete(attribute.to_s)
    end

  end

end


Please note that changing the regex for login validation may cause problems
in other parts of your app.

Thanks,
Bruno



On Wed, May 5, 2010 at 3:39 AM, Ansar.ich <[email protected]> wrote:

> Hi all!
> I need to overload reg exp filter for login name in user.rb model,
> So when I create new user.rb in /root/app/models/user.rb with only
>
> class User < ActiveRecord::Base
>    validates_format_of       :login, :with => /^[\s\.A-Za-z0-9_-]+$/
> end
>
> this does not affect filtering of login field, I have to change
> filtering in community engine user.rb file.
>
> Is it possible to somehow override validation of login?
>
> --
> You received this message because you are subscribed to the Google Groups
> "CommunityEngine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<communityengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/communityengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"CommunityEngine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/communityengine?hl=en.

Reply via email to