我的问题是:下面的代码工作正常,但有一个特例。如果item的product_id为1,则item最多可包含10个关键字。任何帮助将不胜感激。谢谢
class Item < ActiveRecord::Base
validates_length_of :keywords, :maximum => 5, :tokenizer => lambda {|str| str.scan(/\w+/) }, :on => :update
end
答案 0 :(得分:1)
validates_length_of :keywords, :maximum => 5, :tokenizer => lambda {|str| str.scan(/\w+/) }, :on => :update, :unless => lambda { |item| item.product_id == 1 }