13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/validates_xml.rb', line 13
def validates_xml(*attr_names)
configuration = { :message => I18n.translate('activerecord.errors.messages')[:invalid],
:on => :save,
:with => nil }
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
validates_each(attr_names, configuration) do |record, attr_name, value|
begin
REXML::Document.new("<base>#{value}</base>")
rescue REXML::ParseException => ex
record.errors.add(attr_name,
"is not valid xml")
end
end
end
|