Andrew Rukin
Andrew Rukin

Reputation: 933

How may I catch and log all exceptions in Rails view (.erb file)

I need a way to catch and log exceptions from Rails views.

Strangly enough, a method in the controller does not get exception, if it happens inside <% %> erb block

Upvotes: 2

Views: 2458

Answers (1)

Andrew Rukin
Andrew Rukin

Reputation: 933

I decided, that the most reliable way is to add a rescue block INSIDE any erb file:

<% begin %>

... ERB file here: html, html, some scripts, HTML

<% rescue => e%>
    <% Mylogger.ErrorERB 'Exception in erb:', e %>
<% end %>

Upvotes: 3

Related Questions