Permalink
Browse files

Adding error helpers

  • Loading branch information...
1 parent 1f1b8c7 commit 5838f2f7f6e2e7913ce4ae656d13c5cad3549bd0 @tannerburson tannerburson committed Apr 28, 2009
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

0 comments on commit 5838f2f

Please sign in to comment.