How can I debug my Rails application which encountered an internal server error? - ruby-on-rails

I am using Rails 4.1 and Ruby 2.1.1 on Ubuntu.
My application is running just fine on the local development environment. When I moved everything to the production environment server, and tried the application URL, I got the following:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
The log file (production.log) has in it something about the migrations, but nothing else.
Where do I get started trying to figure out what this is about?

From original poster:
I followed the instructions and set up an environment variable for the secret_key. It turns out Rails 4.1 cannot read it and this seems to be a known issue. So, I had to put the key directly into secrets.yml and this solved the problem

Related

Rails test unit access denied rename

I'm new here. I search everywhere and I haven't found anything. I'm using rails on windows 10. I'm following the basic tutorial of a sample app. When I execute "rails test" command in the console I get the following errors. I checked the permissions of each file and directory and all have the permissions needed. Can someone help me ?
I'm using rails 6.0.2.2 version.
Hope I'll get answer here.
Solution : I installed ubuntu on windows 10.
Stop your rails server before executing your tests: the server is keeping cache files locked and the testing framework is trying to alter them.
I encountered the same issue (while following what's probably the same tutorial you were following) on Rails 6.0.3.4 on Windows 10 and doing so solved it. (launching the server again before executing tests reproduced it again)
Update: I thought this was a complete solution, but it's more complex than that. Here's my experience:
running rails test while rails server is running results in the error;
running rails test when rails server is not running sometimes results in the error.
I haven't encountered this error on Linux so far, so my guess is that the implementation of Rails of Windows is unstable and sometimes gets stuck locking its own files.
You can check if you can reproduce the same behaviour, but I would report it as a bug.

mongodb connection error in Rails

I am getting following error while connecting to mongodb using rails console :
Getting Error Mongo::Error::NoServerAvailable: No server is available matching preference: # using server_selection_timeout=30 and local_threshold=0.015
This happens when I switch my rails application.
It is working fine in another rails application(which I was working on for a while) console but when I try to use it in another rails application it gives above error.
I have checked my mongo server it is running and I have also checked my mongoid.yml file configuration. Everything seems fine.
I am a newbie on rails.
Any help would be appreciated. Thanks in Advance

Cloned a RoR server and now getting "we're sorry, but something went wrong error"

I have a working RoR app that's running on Ubuntu Server, served by Nginx and Unicorn. It's using a local postgres database. I also think it's running on Sinatra instead of rails, but I'm too new to RoR to be able to say for certain.
I am attempting to create a development copy of the app to do some testing with. I'm able to do so using the source code, bundle install, and then running webbrick on my desktop. However, my developer wants to duplicate the environment that the actual production copy is running in. I cloned the server hosting the application, but when I browse to the server I get the dreaded "We're sorry, but something went wrong" error.
Here's what I've checked so for. I looked at the log files in the app/logs directory, and those haven't been updated in the last 6 days, so I suspect nothing relevant will be in them. If I run "service nginx status", it appears to be started. The database is running, and I can access it through the psql interface. Again, I'm pretty much an RoR newb... I was hoping one of you kind folks might give me some advice. Where should I look next? I'm sure it's something simple that I'm just overlooking. Thanks in advance!
In your config > environments > production.rb file change the consider_all_requests_local variable to true.
config.consider_all_requests_local = true
FYI, unicorn was not starting along with NGINX. I was able to script unicorn to start on boot, and this fixed my problem.

No log messages in production.log

I wrote a demo HelloWorld Rails app and tested it with WEBrick (it doesn't even use a DB, it's just a controller which prints "hello world"). Then I tried to deploy it to a local Apache powered with Passenger. In fact this test is just to get Passenger working (it's my first deploy on Apache). Now I'm not even sure that Passenger works, but I don't get any error on the Apache side.
When I fire http://rails.test/ the browser shows the Rails 500 error page - so I assume that Passenger works. I want to investigate the logs, but it happens that production.log is empty! I don't think it's a permission problem, because if I delete the file, it is recreated when I reload the page. I tried to change the log level in conf/environments/production.rb, tried to manually write to log file with Rails console production and
Rails.logger.error('asdf')
it returns true but nothing gets written to production.log. The path (obtained per Rails.logger.inspect) is correct, and I remark that the file is recreated if I manually remove it. How can I know what's going on?
(I already checked the Apache logs, plus I set the highest debug level for Passenger but it seems a Rails problem, so is not logged by the server)
Assuming you're running Rails 3.2.1, this is a bug. It was patched in 3.2.2.
If you can't upgrade to 3.2.2 for any reason, this comment on GitHub has a workaround:
# config/initializers/patch_rails_production_logging.rb
Rails.logger.instance_variable_get(:#logger).instance_variable_get(:#log_dest).sync = true if Rails.logger
Setting this works on Rails 3.2.11:
Rails.logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log","production.log"))

Having problems deploying a Rails app to Fedora 8 w/Passenger

I'm using Capistrano and have everything configured. The weird issue I have is that before, I got a nice Passenger error saying what was wrong (I hadn't fully uploaded my vendor/rails directory). After I do that, however, I'm now getting the general Rails We're sorry, but something went wrong 500 error instead of the Passenger error page. My production log shows nothing (only that the log was created). Apache logs show nothing. I don't get why I'm no longer seeing the Passenger error that tells me exactly what is wrong; fixing the error Passenger was complaining about shouldn't prevent it from getting there, should it?
Can anyone help me?
FYI I'm running several PHP-based applications on the same server, with the rails app set as a subdomain (e.g. railsapp.mydomain.com). The full stack is:
Fedora Core 8
Apache 2.2.9
MySQL 5.0.45
Rails 2.3.4
Passenger 2.2.5
You have two issues at hand:
You're log file isn't writable by Passenger. Passengers runs as Apache. So make sure the webserver has the correct rights to write to the log/ directory.
You are probably missing a gem, database or configuration file. Can you start a console session?
./script/console production

Resources