I'm running a Rails 3.0.7 app with nginx and Passenger. I have a custom 500 page that is properly displayed when the app encounters an 500 internal error, however the actual '500' status is not being output to the logs.
I'd like to be able to periodically grep the logs to find 500 errors, but I can't seem to figure out why the actual status is not being rendered. I've even looked through the Rails code, and everything looks fine. All other status codes are successfully logged.
Here is an error-free 200 response:
Completed 200 OK in 1265ms (Views: 1262.4ms | ActiveRecord: 69.6ms | Sphinx: 0.0ms)
Here is a 500 response:
Completed in 500ms
It appears that something is supposed to be there, but is not, so spaces are output instead.
Looks like this has been resolved in Rails master, but is not in the gem for 3.0.7 yet.
https://github.com/rails/rails/commit/7927fc2ff77543a0ab151ac1cb3d60318e2dfa68
Related
ERROR MSG:
Error: Request failed with status code 500
Stack trace:
[42]/</t.exports#http://crdwk.herokuapp.com/packs/bundle-ecc8ea14dbe153e50352.js:1:89311
[42]/</t.exports#http://crdwk.herokuapp.com/packs/bundle-ecc8ea14dbe153e50352.js:1:251725
[42]/</t.exports/</d[h]#http://crdwk.herokuapp.com/packs/bundle-ecc8ea14dbe153e50352.js:1:88311
Ruby version: 2.3
Rails version: 5.1
I have a server-side rendered, client-side hydrated React/Rails app (using gem 'react-rails').
I added the gem 'rack-cors' plus setup in application.rb in order for my requests to work (I'm using axios). However, signing out (a DELETE request) fails and hitting refresh erases the current user. Neither issue occurs locally/in development.
Here's the app: http://crdwk.herokuapp.com
And the repo: https://github.com/English3000/crdwk
I took a look at my Heroku logs:
Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `reset_token' for nil:NilClass):
app/controllers/application_controller.rb:29:in `sign_out'
app/controllers/api/sessions_controller.rb:3:in `destroy'
Given that hitting refresh, the current user does not persist, the issue is the current user somehow isn't getting set.
However, this is not an issue in development. Why would that be?
Looking through my project, the only difference I can find on the backend as compared with a client-side rendered one (which I literally copy & pasted the code for this project from) is this line in application_controller.rb:
skip_before_action :verify_authenticity_token
However, if I comment out this line, when I try to sign up, I get the server error
Started POST "/api/users" for 127.0.0.1 at 2018-03-05 12:16:57 -0800
Processing by Api::UsersController#create as JSON
Parameters: {"user"=>{"email"=>"", "password"=>"[FILTERED]"}}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)
ActionController::InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken:
This is a result of using gem 'react-rails'. (I don't get this error for my other client-side rendered project.)
There isn't an "authenticity_token" parameter.
I find these two resources: Rails security and Learnetto's how-to.
So I add these two lines of code from the second artilce to my api.js:
const csrfToken = document.querySelector("meta[name=csrf-token]").content;
axios.defaults.headers.common["X-CSRF-Token"] = csrfToken;
Now my web app works with the extra application_controller.rb line commented out. EXCEPT, I can't use the DOM to grab the csrf token for my React Native version, so I now have the same issue for mobile...
I'm migrating a working Rails 3 application from server to another type of service. Firstly I had issues with static files (e.g. application.css, application.js) not being rendered (404 status). I resolved that issue turning the config.assets.enabled to true.
Now I'm having the problem of error 500 no matter where I go in the application. I assume it's an asset problem. I don't get an error in log/production. Only something as follow:
Started GET "/" for 187.39.38.147 at 2016-06-14 12:33:05 +0000
Processing by BooksController#index as HTML
Rendered myapp/layouts/500.html (0.7ms)
Completed 404 Not Found in 16ms (Views: 10.0ms | ActiveRecord: 1.9ms)
I have no idea of how to find out what's wrong to fix that.
What can I do to find out what's wrong ?
I have an application running on NGINX/Passenger in production environment. Most of the pages render fine, but some do not. The server returns the static 404 error page, but when checking the production log, the following is appended:
Started GET "/upload" for 92.111.174.132 at 2015-11-26 14:07:50 +0000
Processing by Upload::StaticController#index as HTML
Rendered upload/static/index.html.erb within layouts/upload (1.1ms)
Completed 500 Internal Server Error in 8.0ms
Note that there are no error messages or backtraces; this is really all there is. I've checked NGINX's error log and it does not report an error. I really don't know where to go from here.
All of my rails 3.2.2 ActiveRecord methods are being executed twice. I noticed that each execution is being processed differently, see the examples I grabbed from the console below...
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:43 -0400
Processing by BillsController#show as HTML
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (2.4ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 47ms (Views: 11.2ms | ActiveRecord: 2.4ms)
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:44 -0400
Processing by BillsController#show as */*
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (1.1ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 33ms (Views: 28.1ms | ActiveRecord: 1.1ms)
Can anyone explain to me why all of my ActiveRecord methods are being executed twice and/or what the difference is between Processing by BillsController#show as HTML and Processing by BillsController#show as */*?
Thanks.
It turns out the problem was actually the JSONView Chrome extension. As it states in the options menu...
Use safe method to parse HTTP response (*)
(*) : safe method forces the browser to send an extra HTTP request to get the raw HTTP content.
After spending days trying to figure out what I was doing wrong in my code, it was actually just chrome!
Hope no one else runs into this stupid issue.
-Jeremy
I've been grappling with this same issue. The HTML Validator Chrome extension is also guilty (with none of the fine print.)
In my case, I'm calling a ModestModel-backed search request, so the first hit (and rendering) was succeeding, followed by a phantom 500 as my non-DB search model was out of scope and nil on the second request.
Thanks, Jeremy!
I encounter a strange Problem with Rails3 and send_data. A simple controller action should just send a small file to the browser:
def download
send_data "test", :filename => "file.txt", :type => 'text/plain'
end
When I click the link to that controller action in the browser nothing happens for almost exactly 120 seconds. After these 120 seconds the file will be downloaded instantly.
The strange thing is, that I can keep on browsing on the other sites of the web app and everything responds within milliseconds. The logfile shows
Rendered text template (0.0ms)
Sent data file.txt (0.8ms)
Completed 200 OK in 24ms (Views: 0.7ms | ActiveRecord: 1.3ms)
Just when i clicked the download link. Nothing is printed to the logfile after theses 120 seconds have passed and the file is actually send to the browser.
I am using Rails 3.0.7, POW and Mongrel on Mac OS X. Tested with Firefox and Chrome.
This was a POW-Problem. A workaround is to use Mongrel or Webrick.
See: github.com/37signals/pow/issues/102