From: Brian Candler Date: 2010-10-22T03:41:56+09:00 Subject: Re: Erb location of exception in template Leslie Viljoen wrote in post #956108: > Hiya! > > Does anyone know how I can find the location in an Erb template file > of a line that caused an exception? > > The result of calling erb.result(binding) in build.rb looks like this: > > ./dgp_api.rb:199:in `type': ArgumentError (ArgumentError) > from (erb):285:in `interpret' > from (erb):285:in `each' > from (erb):285:in `interpret' > from build.rb:26:in `interpret' > from build.rb:41 > > > I want to know which template line caused the exception in dgp_api.rb. > If this can't be done with erb, can it be done with eruby or erubis? erb can definitely do it, at least the command line tool can: $ erb hello world <% foo %> the end ^D -:3: undefined local variable or method `foo' for main:Object (NameError) So try looking at the source for that (it's /usr/bin/erb on my Ubuntu box). The following code works for me: require 'erb' src = < the end EOS erb = ERB.new(src) puts erb.result #Result: #(erb):3: undefined local variable or method `foo' for main:Object (NameError) This is with: $ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] HTH, Brian. -- Posted via http://www.ruby-forum.com/.