Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 带有关联的rails activerecord验证_Ruby On Rails 3_Validation - Fatal编程技术网

Ruby on rails 3 带有关联的rails activerecord验证

Ruby on rails 3 带有关联的rails activerecord验证,ruby-on-rails-3,validation,Ruby On Rails 3,Validation,我有如下示范协会: class Group < ActiveRecord::Base has_many :group_links, :dependent => :destroy end class GroupLink < ActiveRecord::Base belongs_to :group validates_presence_of :group_id validates_presen

我有如下示范协会:

     class Group < ActiveRecord::Base
       has_many :group_links, :dependent => :destroy
     end

      class GroupLink < ActiveRecord::Base
       belongs_to :group
       validates_presence_of :group_id
       validates_presence_of :url, :message => "We need a url to create a link"
       validates_uniqueness_of :url, :message => "A link with this url already exists"
       validates_presence_of :text, :message => "We need a text to create a link"
       validates_uniqueness_of :text, :message => "A link with this text already exists"
      end
类组:销毁
结束
类GroupLink“我们需要一个url来创建链接”
验证以下内容的唯一性::url,:message=>“具有此url的链接已存在”
验证是否存在:text,:message=>“我们需要文本来创建链接”
验证:text、:message=>“与此文本的链接已存在”的唯一性
结束
我希望它像在每个小组的工作组链接应该是唯一的。不管它的工作方式如何,它都会抛出验证错误,即使其他组有thins group link

我做错了什么


提前感谢,

我使用:scope=>:group\u id进行唯一性验证,以使其正常工作