In the Sinatra ruby framework, I have a route like this:
get '/portfolio/:item' do
haml params[:item].to_sym
end
This works great if the template that exists (e.g., if I hit /portfolio/website
, and I have a template called /views/website.haml
), but if I try a URL that doesn't have a template, like example.com/portfolio/notemplate
, I get this error:
Errno::ENOENT at /portfolio/notemplate
No such file or directory - /.../views/notemplate.haml
How can I test and catch whether the template exists? I can't find an "if template exists" method in the Sinatra documentation.