Reputation: 1
I have a problem in displaying the error message in Ruby on Rails. I am using:
rescue => Exception ex
#display ex.message
The output I get when I tried to display it in an alert messagebox is this:
"DBI::DatabaseError: 37000 (50000) [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot approve records for the specified date..: Exec uspTestProc 279, 167, 2."
It displays some words that are not friendly to users. What I want is to display only these words: "Cannot approve records for the specified date"
Upvotes: 0
Views: 1437
Reputation: 46914
I think an error like that can be catch by rescue_from
class ApplicationController
rescue_from MyException do
render :text => 'We have some issue in our database'
end
end
Upvotes: 1
Reputation: 1417
Common practice in Rails is to use the "flash" session variable within the Controller:
# error catching logic goes here
flash[:error] = "There was an error!"
# notice logic goes here
flash[:notice] = "I am sending you a notice."
Then display it (possibly within a catchall layout):
<% if flash[:error] %>
<div id="error"><%= flash[:error] %></div>
<% end %>
<% if flash[:notice] %>
<div id="notice"><%= flash[:notice] %></div>
<% end %>
Was that what you are looking for?
Upvotes: 1
Reputation: 239810
In any language, I would usually always handle the exceptions and show the user a dumbed down version.
Users shouldn't get to see the inner workings of something and exceptions are a great way to show them a big mess of nonsense.
I:
Upvotes: 0