简体   繁体   中英

Heroku giving 500 error with little information + asset files are empty [Rails]

I've just deployed a Rails app I'm working on to Heroku - http://sports-site.herokuapp.com/ .

Here's the updated GitHub - https://github.com/adamzerner/sports_site .

  1. application-*.css and application-*.js both are empty in production, but the CSS and JS work perfectly in development.

  2. Almost every page I visit (except the home page and the madden rankings page) give me a 500 error. And the logs are hardly giving me any information. Below is all I get:

    2014-09-09T21:34:09.019757+00:00 heroku[router]: at=info method=GET path="/spurs" host=pure-everglades-8286.herokuapp.com request_id=d6a0348f-db82-4519-844d-d85973c75413 fwd="67.86.210.96" dyno=web.1 connect=1ms service=11ms status=500 bytes=1002 2014-09-09T21:34:09.323769+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=pure-everglades-8286.herokuapp.com request_id=934ea050-cbab-4c26-b925-5bc5f2d16369 fwd="67.86.210.96" dyno=web.1 connect=1ms service=9ms status=500 bytes=858

How can I solve these two issues?

Edit: I think these two issue might be related. When I open up Chrome's dev tools and go to the resources tab, It says:

Failed to load resource: the server responded with a status of 500 (Internal Server Error

underneath

<link data-turbolinks-track="true" href="/assets/application-1babc5fe447a141359d73e5a3339663c.css" media="all" rel="stylesheet" />

and

<script data-turbolinks-track="true" src="/assets/application-f3556e3d9d239b5384897deb4b41e10f.js"></script>

Edit :

When I go to http://sports-site.herokuapp.com/trailblazers/lamarcus_aldridge I get this error.

undefined method `name' for nil:NilClass

referring to this line

<h1><%= @player.name %> <small><%= link_to "#{@player.team.location} #{@player.team.name}", "/#{@player.team.name.downcase}" %></small></h1>

I don't understand why this is happening. I don't know if it's saying player is nil or team is nil , but neither seems to be according to this console output:

`2.1.2 :001 > l = Player.where("name like ?", "%lamarcus_aldridge%")[0]
Player Load (14.8ms)  SELECT "players".* FROM "players"  WHERE (name like '%lamarcus_aldridge%')
 => #<Player id: 383, team_id: 29, position_id: 4, position_rank: 2, overall_rank: 6, analysis: "Star player.|\n\tGood size and strengt
.
.
.
2.1.2 :002 > l.name
 => "LaMarcus Aldridge"
2.1.2 :003 > l.team.name
  Team Load (0.4ms)  SELECT  "teams".* FROM "teams"  WHERE "teams"."id" = ? LIMIT 1  [["id", 29]]
 => "Trailblazers"`

Your app loads okay, which means your problem is likely a small niche issue which inside your app itself.

Let me help you debug:


Errors

As Heroku is a platform as a service , it will show you two types of error -

  1. Platform ("Heroku") errors
  2. Syntax ("Rails") errors

In order to ensure you're able to get things working correctly, you need to appreciate these two types of error & how to tackle them:

-

Heroku

在此处输入图片说明

This is a Heroku error - caused by a problem on the Heroku platform itself. If you have this error, it means that your application will not be able to run at all, as you've got an issue with Heroku. The likely problem here is that Heroku doesn't have the correct database / configuration credentials, preventing it from loading your app

If you have a Heroku error, it means you have to set up your application correctly. Fortunately, you don't have this, which means you can focus on the next type of error:

-

Rails

在此处输入图片说明

The Rails error is what you have.

Basically, this is when you have your application working well on the Heroku platform, but have issues with the Rails backend. The issue can be systemic (to do with the system), or "syntaxic" (to do with your syntax)

To fix these errors, you need to make sure you have all the files, dependencies & ENV variables set up correctly.


Fix

Looking at your application, there is likely a deeper issue to contend with.

I originally thought it would be a problem with your assets, but as your other pages are showing the error, too, we need to establish what the problem is.

The simplest thing you can do is to turn your development environment on for Heroku:

#config/environments/production.rb
config.consider_all_requests_local       = true # false

> $ git add .
> $ git commit -a -m "Local Debug"
> $ git push heroku master

YOU MUST CHANGE THIS BACK AFTER DEBUGGING

This will give you the ability to actually see what the errors are. I would guess it's either a controller issue, or something to do with database data (perhaps you haven't migrated when you pushed to Heroku) etc.

If you use the above, push your code to Heroku, you'll be able to see the errors your app is invoking. This will, in turn, allow you to remedy the issues specifically

That's the best I can do with what you've provided so far. If you update our question, I'll be in a much better position to provide specific advice!

As to your second problem, when you change your rails app environment, this also changes the database that it connects too. So first, are you sure you're running the app and the rails console under the same environment?

Having said that, we would need to see your controller action (where you set @player). The snippet you pasted from your console doesn't mean you're doing it right in your controller.

A Heroku 500 error is the standard Heroku error. You have to check your logs to get the actual error. The link below will give you more information on the error Heroku puts in your log. https://devcenter.heroku.com/articles/error-codes

In the terminal cd into your app and type heroku logs --tail That will give you the live logs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM