Logging stacktraces when running a Rails app on Thin - ruby-on-rails

This is probably something stupid as I have never deployed a Rails app before. However:
I developed the app using WEBrick. When I got an exception, I'd get a helpful stacktrace in the console. Now I am deploying the app to Thin, running as a Windows service (I am not using Windows by choice, I hasten to add).
When the app gets an exception running in Thin, all I get in the logs is: Completed 500 Internal Server Error in 31ms. No stacktrace or description of the error. When I run it in Thin in the console I get a description of the error, but no class name or line number. I'm sure it's some simple config but a bit of googling has turned up nothing so far. Can anyone shed any light on how to get more informative error logging?
On a related note, what's the simplest and best way to set up email notifications on error in a Rails app?

Ignore me - I was being stupid. I created some extra environments for the app (a sales and a uat environment) and foolishly copied config/environments/test.rb which has
config.action_dispatch.show_exceptions = false
and I now feel quite foolish.

what's the simplest and best way to set up email notifications on error in a Rails app?
The exception_notification gem.

Related

Rails annoying message We're sorry, but something went wrong

****We're sorry, but something went wrong.
If you are the application owner check the logs for more information.****
On various rails applications I have been getting this all the time. How can this be fixed for good on ruby on rails apps?
You will have to check the log and fix the error, for production application you can use services like airbreak or errbit a free solution. Whenever this page occurs you will receive full trace and error. Hope this will help you in making application much more stable.

How to set a custom error page with passenger and apache

I am using Capistrano,Apache 2 and Passenger to rollout my rails applications on a weekly basis, this works well. Recently I encountered an error where the passenger side of the deployment exposed my stack trace and my server information, I was able to do a rollback and it was only exposed for a moment, but a moment is still venerable.
So:
How do I disable this?, I have see this so that might answer that question but it leads to more:
I want to use some Rails Custom error pages to display errors for all the 500's and the 404, essentially if passenger explodes or you encounter a broken route (so a rails error) I want you to see a custom error page, not a rails error page, not a passenger error page.v I was reading this documentation on passenger and apache but it didn't provide any examples of how you might do this.
My goal is that if for some reason you encounter a rails error or a deployment goes wrong that you don't see the rails stack trace or the passenger stack trace. that you see, instead, a custom error page.
Nice thing to do during a deployment process is to redirect any requests to a static page saying "We'll be back in 10 minutes". You can follow this answer to do it manually or use a gem capistrano/maintenance. The idea is that you'd have a capistrano task. By running this task a static html page is being created on the server in public directory. Apache is configured to watch whether this page exists, and if it does - all requests are redirected to it with 503 status.

how to debug web server on RoR?

I currently have a problem with a project.
it freezes before it shows the "Started GET ...." seems like it hits an infinite loop.
now i dont really have much experience with debuggers in ROR, can anyone recommend anything i can use to trace the exact origin of the problem. if i can get an error code somewhere then i might be able to fix it.
currently i am using webrick, i tried thin and it gave the exact same error.but i am willing to use anything to find the exact origin of this error.
it seems to be related to the project because all other projects works fine on my environment.
Take a look at the Rails guide on debugging.
Also try running the Rails console ("rails c"); if you can get to a command prompt at all that means that the issue is not in loading the Rails environment (e.g. a problem in application.rb) but is somewhere in the process of making a web request. If there's a failure it may give you a better error message.

Passenger "No such file to load" error for Model

I'm having a problem with deploying a Rails 3 app to a Passenger/Apache2/RVM server running Ubuntu 11.10.
I'm getting the error:
A source file that the application requires, is missing.
...
Error message: No such file to load -- Goal
Exception class: LoadError
Goal is one of my Rails Models.
I've seen a lot of people with a similar error message, but their issues seem to relate to missing bundles/gems - not model files! Their problems were resolved by ensuring permissions were set up correctly, so to that end I've got:
Apache running as www-data, as is Passenger. RVM is installed as www-data and I've chown'd the entire web app directory to www-data.
I've been wrestling with this for some time now and am really out of ideas - if anyone has any suggestions I'd be very grateful!
You might probably have the file structure of your Rails app wrong. Are you sure you have the "goal.rb" file within {your_app_root_url}/app/models/ ?
To me, if I am seeing the error when you view the app in browser, it seems like your rails app and passenger(with apache2) are working fine. The other possibility is you might be looking at wrong app folder which passenger is set up to.
It's hard to tell what's wrong. Please provide more details of how you set up your passenger with your rails app directory. Also it would help if you could show what's inside your app (app structure) and what's inside goal.rb model file.
Well I've solved it. Turned out that a work around for a problem with yaml encoded model archives (i.e. an explicit require of Goal) in a completely unrelated Model was causing the error to appear. Looks like it only rears its head in production - probably due to the differences between the class loaders used in development vs. production.
Tough one to find... the stack trace didn't include a reference to where the problem actually was!

How to deploy a Rails app to Dreamhost?

I'm kind of lost, I try to deploy my application on a shared dreamhost server.
Now everything works fine locally. It's my first try at Rails, and I'm not really a programmer or sysadmin, just hacking something together.
On Dreamhost, if I start webrick, it works fine on port 3000, but webricks gets killed pretty quickly, I guess that makes sense.
So what do I have to do to make it run?
I enabled fastcgi support and mod_rails.
Now, how do I get the app constantly running?
I keep reading about having to do things to .htaccess and to dispatch.fcgi.
But I can't find any dispatch file in my rails app (2.3.2).
Do I have to create that one manually? Doesn't really feeld very rails-like to me. I didn't really manage to find out what this dispatch file does, and why it's needed.
Any help would be greatly appreciated.
I looked at the DH Wiki, but couldn't figure it out (http://wiki.dreamhost.com/Rails)
Additions:
I enabled mod_rails and pointed to the public directory (I had already done that).
I keep getting an error: screencast.com/t/KamqVawk
Hm, server logs look like there is actually no request, so this might be a problem on dreamhosts end. It's strange I see that the access.log show a new change date, when I try to access the page, but there is no request noted, error.log is empty too.
Dreamhost Support Answer:
The server was up to date, so that wasn't the problem.
They proposed freezing the Gems, which I did (see: http://wiki.dreamhost.com/Freezing_Gems)
But it didn't help.
I guess I'm giving up, and looking into hosting which is specialized for rails.
Thx for all your help!
Changed to hostingrails.com
I got the app working on hostingrails.com, passenger on hostingrails.com showed me errors, which weren't shown by dreamhost or mongrel. By correcting these errors, I got the app working.
Dreamhost won't let you use webrick if you're using shared hosting. You can either use FastCGI or Passenger to host Rails on shared DH (mongrel is an option if you upgrade to DreamhostPS, but that's obviously more expensive).
For FastCGI, you will need a dispatch.fcgi file (older versions of Rails would generate one when you created a new Rails app, but that stopped around 2.2 if I remember correctly) as well as code in your .htaccess to send requests to the dispatcher. See the Dreamhost Ruby on Rails wiki page for details about setting up FastCGI.
The more preferable option is to set up your application to run on Phusion Passenger (aka mod_rails). It should be pretty simple through your Dreamhost panel, you just need to enable the domain to use mod_rails, and then set the directory for the domain to the public directory of your application. See the Passenger wiki page for more details.

Resources