Skip to content

Commit

Permalink
Adding error helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerburson committed Apr 28, 2009
1 parent 1f1b8c7 commit 5838f2f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions error_helpers.rb
Original file line number Diff line number Diff line change
@@ -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.