1
我正在使用简单的表单,并希望为用户模型添加validates_presence_of:介绍验证。富文本编辑器的Rails活动记录验证
= f.input :intro, :as => :rich_text_editor, :input_html => {:rows => 6}
的问题是,在默认情况下HTML标记BR传中PARAMS同时节省了引进的用户和 确认存在不工作。
我正在使用简单的表单,并希望为用户模型添加validates_presence_of:介绍验证。富文本编辑器的Rails活动记录验证
= f.input :intro, :as => :rich_text_editor, :input_html => {:rows => 6}
的问题是,在默认情况下HTML标记BR传中PARAMS同时节省了引进的用户和 确认存在不工作。
而不是做一个简单的validates_presence_of可以实现自己的验证的,你的情况可能是这样的:
class YourModel < ActiveRecord::Base
validates_each :intro do |record, attribute, value|
if value.blank? || value.strip == "<br/>"
model.errors.add(attribute, :blank)
end
end
end
,然后你将有验证工作,你所期望的方式。
嗨Mauricio,谢谢你的回复。它为我工作。 – 2012-04-05 16:17:01