Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding error helpers

  • Loading branch information...
commit 5838f2f7f6e2e7913ce4ae656d13c5cad3549bd0 1 parent 1f1b8c7
@tannerburson tannerburson authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 error_helpers.rb
View
32 error_helpers.rb
@@ -0,0 +1,32 @@
+module Sinatra
+ module Plugins
+ module ErrorHelpers
+
+ def errors_for(field)
+ out = ''
+ if !flash[:error].nil? && !flash[:error][:errors].nil? && flash[:error][:errors].respond_to?(:on) && !flash[:error][:errors].on(field).nil?
+ out << '<span class="error">'
+ out << flash[:error][:errors].on(field).join("<br/>")
+ out << '</span>'
+ end
+ end
+
+ def value_of(field)
+ if !flash[:error].nil? && !flash[:error][:object].nil?
+ flash[:error][:object].send(field.to_sym)
+ else
+ nil
+ end
+ end
+
+ def error?(field)
+ if !flash[:error].nil? && !flash[:error][:errors].nil? && flash[:error][:errors].respond_to?(:on) && !flash[:error][:errors].on(field).nil?
+ 'error'
+ else
+ ''
+ end
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.