how do i display error messages in the web browser when using rails?
eg. if i use a variable in the view that i hasn't defined in the controller i want to get an error message.
thanks
how do i display error messages in the web browser when using rails?
eg. if i use a variable in the view that i hasn't defined in the controller i want to get an error message.
thanks
In your controller:
def your_method
#processing that fails
flash[:notice] = 'your error message'
end
In your view:
<% if !flash[:notice].nil? %>
<p id="notice"><%= flash[:notice] %></p>
<% end %>
The documentation for the Flash hash is available here.
To rescue from errors at the application level rather than displaying error messages to the user, you can use
rescue_from ErrorType, :with => :action_method
Examples:
http://stackoverflow.com/questions/101012/customising-the-generic-rails-error-message
http://www.perfectline.co.uk/blog/custom-dynamic-error-pages-in-ruby-on-rails
When you have errors like the mentioned one, when you try to reach the respective page you should have an error message instead of the proper page.