Here is a code used to display error messages
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
unless html_tag =~ /^<label/
"<span class=\"field_with_errors\">#{html_tag}</span>".html_safe
else
"#{html_tag}".html_safe
end
end
However, it’s better to not use unless and else together. So I did
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
if html_tag !=~ /^<label/
"#{html_tag}".html_safe
else
"<span class=\"field_with_errors\">#{html_tag}</span>".html_safe
end
end
and it’s not working.
I know this is because of "!=~".
Well, how do I change it to make it work?
You should just use
=~. The following gives the same result as your original code withunless: