Rails Exception Handler, Creating Exceptions Page
TAGS:
ruby rails exception handler
Series:
Creating View For Exceptions.
First, Assign all exceptions from the ErrorMessage model to an instance variable @errors in the posts controller to be accessed in errors page in views as:
def errors
@errors=ErrorMessage.all
endThen, Make a route before posts to avoid id exception as:
get "posts/errors"
root to: "posts#index"
resources :postsThen, Create views/errors.html.erb and paste the next code and save.
<h1>Errors</h1>
<table border="2">
<tr>
<% @errors.attribute_names.each do |key,value| %>
<th>
<%= key %>
</th>
<% end %>
</tr>
<% @errors.each do |error| %>
<tr>
<% error.attributes.each do |key,value| %>
<td>
<%= value %>
</td>
<% end %>
</tr>
<% end %>
</table>You can use any paging gem to handle large exceptions.
Now, Take a look to this tutorial video :
Great Note, Every time you change any file in config/initializers, You must restart server.