Module: Happy::Errors
- Defined in:
- lib/happy/errors.rb
Defined Under Namespace
Class Method Summary collapse
- .friendly_message_for(msg) ⇒ Object protected
- .h(t) ⇒ Object protected
-
.html(exception, controller, options = {}) ⇒ Object
Render a HTML page for the given exception.
Class Method Details
.friendly_message_for(msg) ⇒ Object (protected)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/happy/errors.rb', line 42 def self.(msg) case msg when /^undefined local variable or method `(.+)'/ "You called a method called \"#{$1}\", and this method did not exist. This could simply be a typo. If it's not, please check that you're calling the method from within the correct scope." when /^undefined method `(.+)' for nil:NilClass$/ "You called a method called <strong>\"#{$1}\"</strong> on <strong>nil</strong>. In most cases, this is due to simple typos; please check your variable names. Otherwise, make sure the receiving object has been initialized correctly." when /^undefined method `(.+)' for (.+)$/ method = $1 var = $2 klass = case var when /^#<(.+):0x.+>$/ then $1 when /^.+:(.+)$/ then $1 else var end "You called a method called <strong>\"#{h method}\"</strong> on an instance of class <strong>#{h klass}</strong>, which doesn't know how to respond to that method. Please check for typos." end end |
.h(t) ⇒ Object (protected)
60 |
# File 'lib/happy/errors.rb', line 60 def self.h(t) ; Rack::Utils.escape_html(t) ; end |
.html(exception, controller, options = {}) ⇒ Object
Render a HTML page for the given exception.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/happy/errors.rb', line 21 def self.html(exception, controller, = {}) = { :title => exception.class.to_s, :message => exception., :friendly_message => nil }.merge() # Load and cache error template. @html = begin File.read(File.(File.join(__FILE__, '../files/error.erb'))) end # Generate friendly message from exception. [:friendly_message] ||= [:message] # Render error page. ERB.new(@html).result(binding) end |