继承模型,然后唯一性验证不起作用

时间:2015-11-17 18:40:00

标签: ruby-on-rails-3 couchrest

我有一个模型V1 :: Profile ::来自V1 :: Profile :: 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

如果我保存了两个具有相同名称的子网,它没有抱怨,如果我保存一个空白名称的子网,它会抱怨,验证存在有效,但不是唯一性,任何人都有想法吗?

1 个答案:

答案 0 :(得分:0)

我发现问题,在V1 :: Profile :: Subnet中,我不应该这样做

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

相反,我应该写:

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

然后它有效。但还是不明白为什么。有人有想法吗?