I want to be able to create multiple user accounts with the same login (because of the case a user deletes his account... and then sign up with the same login). I am using authlogic and rails3_acts_as_paranoid.
But there is a problem: Authlogic validates the uniqueness of the login field - and IGNORES 开发者_如何学运维the default_scope(:conditions => {:active => true}).
(see further details of invalid bug report: https://rails.lighthouseapp.com/projects/8994/tickets/4064-validates_uniqueness_of-should-honor-default_scope-or-not )
I didnt find out how to tell validates_uniqueness_of to use the default scope... Can you help me?
Validation
ActiveRecord's built-in uniqueness validation does not account for records deleted by ActsAsParanoid. If you want to check for uniqueness among non-deleted records only, use the macro validates_as_paranoid in your model. Then, instead of using validates_uniqueness_of, use validates_uniqueness_of_without_deleted. This will keep deleted records from counting against the uniqueness check.
class Paranoiac < ActiveRecord::Base
acts_as_paranoid
validates_as_paranoid
validates_uniqueness_of_without_deleted :name
end
Paranoiac.create(:name => 'foo').destroy
Paranoiac.new(:name => 'foo').valid? #=> true
good luck
精彩评论