Thursday, 15 July 2010

ruby on rails - How to validate ERB or capture an ERB SyntaxError -



ruby on rails - How to validate ERB or capture an ERB SyntaxError -

using rails 3.2.x , ruby 1.9.3

given mal-formed erb template, how can 1 of following:

validate template , raise error if bad capture syntaxerror erb throws when seek result of bad template.

i think work:

template = "hello <%= @planet name %>" @planet_name = "earth" begin erb.new(template,nil).result(binding) rescue raise standarderror, "bad erb template" end

but not. instead syntaxerror erb.

is there way capture/validate these errors?

specifically rescuing syntaxerror turns out trick.

begin erb.new(template,nil).result(binding) rescue syntaxerror raise standarderror, "bad erb template" end

ruby-on-rails ruby error-handling erb

No comments:

Post a Comment