2015-11-17 34 views
0

我有一個模型V1 ::從V1 ::個人資料檔案::子網繼承:: Base的繼承模型,那麼唯一性驗證不起作用

module V1 
    class Profile::Subnet < V1::Profile::Base 
    end 
end 

示範基地:

module V1 
    class Profile::Base < CouchRest::Model::Base 
    use_database $DATABASE_AV_TESTS 
    property :name, String 
    validates :name, :presence => {:message => 'cannot be blank, Profile not saved'}, 
         :uniqueness => {:message => 'Profile name must be unique, Profile not saved'}, 
         :length => {:maximum => 255, :message => 'is too long (maximum is 255 characters)'} 
    validates :author, :presence => {:message => 'cannot be blank, Profile not saved'} 

    end 
end 

如果我保存了兩個具有相同名稱的子網,它沒有抱怨,如果我保存一個空白名稱的子網,它會抱怨,驗證存在有效,但沒有唯一性,任何人有想法?

回答

0

我發現這個問題,在V1 ::檔案::子網,我不應該做

module V1 
    class Profile::Subnet < V1::Profile::Base 
    end 
end 

相反,我應該寫:

class V1::Profile::Subnet < V1::Profile::Base 
end 

然後,它的工作原理。但仍然不明白爲什麼。任何人有想法?

+0

現在,它不工作〜 – user2569579