mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-05 16:00:00 +01:00
29 lines
915 B
Ruby
29 lines
915 B
Ruby
module ApplicationHelper
|
|
|
|
# add this to app/helpers/application_helper.rb
|
|
# http://www.emersonlackey.com/article/rails3-error-messages-for-replacemen
|
|
def errors_for(object, message=nil)
|
|
html = ""
|
|
unless object.nil? || object.errors.blank?
|
|
html << "<div class='formErrors #{object.class.name.humanize.downcase}Errors'>\n"
|
|
if message.blank?
|
|
if object.new_record?
|
|
html << "\t\t<h5>There was a problem creating the #{object.class.name.humanize.downcase}</h5>\n"
|
|
else
|
|
html << "\t\t<h5>There was a problem updating the #{object.class.name.humanize.downcase}</h5>\n"
|
|
end
|
|
else
|
|
html << "<h5>#{message}</h5>"
|
|
end
|
|
html << "\t\t<ul>\n"
|
|
object.errors.full_messages.each do |error|
|
|
html << "\t\t\t<li>#{error}</li>\n"
|
|
end
|
|
html << "\t\t</ul>\n"
|
|
html << "\t</div>\n"
|
|
end
|
|
html
|
|
end
|
|
|
|
end
|