【发布时间】:2012-09-07 11:25:31
【问题描述】:
我有产品和品牌 产品型号:
class Product < ActiveRecord::Base
attr_accessible :brand_id, :title
belongs_to :brand
validates :title, :presence => true
validates :brand, :presence => {:message => 'The brand no exists'}
end
和品牌模型
class Brand < ActiveRecord::Base
attr_accessible :name
validates :name, :presence => true
has_many :products, :dependent => :destroy
end
我想验证是否存在具有该品牌名称的产品。 我的意思是我可以有 2 个不同品牌的同名产品,但不是同一个品牌。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 belongs-to