Rails验证唯一性不起作用

时间:2011-12-03 19:18:09

标签: ruby-on-rails ruby ruby-on-rails-3

模型代码(试图要求embed_code的唯一性)

https://gist.github.com/1427851

class Link < ActiveRecord::Base
  validates :embed_code, 
            :format => {:with => /^<object type|^<embed src|^<object width|^<iframe src|^<object height|^<iframe width|^<embed id|^<embed width|^<object data|^<div|^<object id/i, :message => "Invalid Input"}, 
            :uniqueness => true
  attr_accessible :title, :embed_code, :score
  after_initialize :calculate_score, :favs_count
  attr_accessor :score, :fav_count
  validates :title, :length => { :in => 4..45, :message => "Must be between 4 & 45 characters"} 


  before_save :resize

  has_many   :favorites
  has_many   :favorited, :through => :favorites, :source => :user
  belongs_to :user

我已尝试validates_uniqueness_of :embed_code并禁用(注释掉)模型的非关键组件,例如:before_save :resize

0 个答案:

没有答案