Reputation: 133
My problem is: the code below works fine but there is one special case. If item's product_id is 1 then item can have up to 10 keywords. Any help will be appreciated.Thanks
class Item < ActiveRecord::Base
validates_length_of :keywords, :maximum => 5, :tokenizer => lambda {|str| str.scan(/\w+/) }, :on => :update
end
Upvotes: 0
Views: 319
Reputation: 222108
validates_length_of :keywords, :maximum => 5, :tokenizer => lambda {|str| str.scan(/\w+/) }, :on => :update, :unless => lambda { |item| item.product_id == 1 }
Upvotes: 1