Rails error routing issue (blank page) - ruby-on-rails

having a weird issue with Rails (3.2.15)
I messed around with nicer error pages, but as that was suppressing ALL errors at one point I needed to revert so I can see errors in the log files.
I had:
installed gem: 'exception_notification'
added initialisation code for that in the relevant environment file (config.middleware...)
added routes to catch errors 'get '/500', :to => 'errors#server_error' ', same for 404/422
added rescue statements in application controller "rescue_from Exception, with: lambda { |exception| render_error 500, exception }" etc, same for 404 and render method to render custom pages
Now, I didn't want any of that any more as stated, so I have removed all of the above, ran bundle install, etc. and deployed to my staging environment.
However, NOW I get blank pages on any errors (500 or 404), I don't see that standard rails 'Something went wrong page' at all, (though it is still in /public)
I don't understand why I'm not back at the default error handling, I have no 'rescue' statements anywhere, and no routes that mess with errors.
The log file on 500 shows the full error that occurs and then just:
rendered [page I was trying to see] within layouts/application (50.4ms)
"Completed 500 Internal Server Error in 184.9ms"
[error details]
Why am I not getting my default Rails error behaviour, I'm not sure what I'm missing here??
Any suggestions greatly appreciated!!

turned out I had forgotten to remove this line in config/application.rb :
config.exceptions_app = self.routes
since I removed any routes to do with errors it was therefore showing blank pages.
d'oh

Related

How do I prevent unwanted routing errors in production

ActionController::RoutingError (No route matches [GET] "/google83362a7a0f381ff0.html"):
I see the above logs in production, how should I prevent it.
If user mistypes a URL, how should I re-direct to a common error page
You can redirect the user to the desire page you want if no route matchs
Write down the following code at the bottom of your routes.rb file
In /config/routes.rb
#If no route matches
match ":url" => "application#redirect_user", :constraints => { :url => /.*/ }
Then redirect the user to the error page in the application_controller.rb file
*In /app/controllers/application_controller.rb*
def redirect_user
redirect_to '/404'
end
You don't need to trigger a controller to do that.
Just add this as the last rule in routes.rb:
match '*path', via: :all, to: redirect('/404')
Rails does this automatically when application running in production mode.When uploading application to live server, Rails takes care of handling those exceptions and rendering the correct error pages with the correct header status.You can directly find the files inside public folder.
Whenever you set up your Rails application on a live server, you give the site root as the /public folder in your application. Then, whenever a request is made to that server address, Web server first looks in that public folder and tries to serve a static asset (this is a configurable option in config/environment.rb). If it can't find the requested page, then the request is forwarded through the Ruby stack.
When in production mode, if Rails encounters an error that isn't handled, it throws the error to the stack, which then tells Web server to render an appropriate error.
Here are some common errors that you'll see in development mode and what they render in production mode:
ActiveRecord::RecordNotFound => 404 (page not found)
nil.method => 500 (server error) unless you turn off whiny nils
ActionController::RoutingError => 404 (page not found)

How to enable development mode or display errors in ruby on rails

When I browse the site I get:
We're sorry, but something went wrong.
as I've seen its a 500.html file, so its some internal server error, but how can I make display those errors?
I've tried this:
1) putting ENV['RAILS_ENV'] ||= 'development'in environment.rb, but nothing happened
2) config.log_level = :any, then looked at the production.log, but there is not 500 errors
Or what I need to write in the 500.html to see errors?, or just display it no matter how.
Your log files (wherever they're written) should contain your errors.
If you still like to view the errors in the browser you could change the following in your environment/production.rb (but consider it as a temporary work-around). Make sure to switch it back.
config.consider_all_requests_local = true

Rescuing a RoutingError in Rails

So, I followed José Valim's blogpost, adding
config.exceptions_app = self.routes
to my application.rb for routing HTTP errors to my own controller.
Everything works just as it's supposed to, my custom error pages work and such, but it throws an ActionController::RoutingErrorthough, which gets logged as FATAL. Is there anyway to get around that FATALmessage? I've been trying to rescue from the error both in the application controller and in my error controller, but to no avail.
2012-06-27 12:19:33.908 [FATAL] [127.0.0.1]
ActionController::RoutingError (No route matches [GET] "/3489423u4023ho")
Did you add a route like match "/404", :to => "errors#not_found"?
Are you using the production mode, or the development mode?
You won’t be able to see your custom exceptions in development unless you set config.consider_all_requests_local to false in your config/environments/development.rb. The reason is, if the request is considered local, Rails will always favor to show the debug exceptions page;

Rails - Create internal server error (500) at localhost

I couldn't see 500 error when I accessed a URL for which there is no Data, rather it was showing the 'Template missing' error. At the same time, when I ran it at the server, it had shown the 500 error. I need to do testing at local machine. So please tell me how I can create such a situation at localhost?
Thanks & Regards,
Rajesh
You can create such situation in localhost if you run the server in production mode: rails s -e production (Of course, if the error is still present)
If you are getting a template missing error is most probably because you are missing the view file for a given controller action
Ex: if you have a controller called users
class UsersController < ApplicatationController
def index
end
end
by default rails is expecting a view in
app/views/users/index.html.erb (or haml)
But if you could post the error log you are getting we might be able to help you more
regards
sameera
It's a simple problem with your corresponding view not being present. Open the control file which corresponds to your url. Then see the action which is being called and then, see if the corresponding view is available in the app/views/ folder.
The reason for 500 error is the same 500 says that there was an internal error at the server side.
Also, don't go about changing the url's charecter and stuff. IT WONT WORK!

rails: displaying a user friendly message for a routing error in rails

i am working in rails 2.3 on mac osx leopard.
every time i type a url that does not exist in a rails application i get the following error
Routing Error
No route matches "/whatever_i_typed" with {:method=>:get}
this is find for development, but i was wondering how i can make sure users see a friendlier 'oops! not found' page. i was thinking about doing a begin...rescue block but i didn't know where to put it, not did i know the error code (i.e ActiveRecord::RecordNotFound)
thanks!
yuval
This error will never appear in production. Instead, users will see the public/404.html page.
To try this out on your localhost, put passenger/mongrel into production mode. Override the local_request? method on your ApplicationController like so:
class ApplicationController
def local_request?
false
end
end
If you'd like to experiment with dynamic behavior you can check out the rescue_from class method on ActionController.
How about
map.connect '*url', :controller => "not_found"
as a last routes.rb entry? I think it should do the trick, shouldn't it?
I found the below url helpful for Rails 3.0.. users.
http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution

Resources