2

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"`

3 Answers 3

3

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

enter image description here

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

enter image description here

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!

4
  • Thanks so much for the help! 1) I did indeed forget to run heroku run rake db:migrate and heroku run rake db:seed. I ran them and it seems to have fixed a few things. 2) I did what you said and it is now showing me errors like it does in development. See the edit to my question. Also, the assets still aren't loading. Commented Sep 10, 2014 at 14:04
  • Does it have something to do with the data folder I have? Commented Sep 12, 2014 at 15:52
  • It shouldn't have any bearing on the issue - what issues do you think it would cause? Commented Sep 13, 2014 at 8:50
  • Just to be clear.. Should I create a file config/environments/production.rb and only insert config.consider_all_requests_local = true # false and then push that? Should that fix so I see errors on FE or in logs now?? I still only see a 500 error in log and no details and FE is the same 500 Server error only
    – OZZIE
    Commented Feb 7, 2016 at 14:12
1
+50

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.

13
  • See the code on github - github.com/adamzerner/sports_site. I don't really know much about environments, so I don't know if they're in the same environment. Commented Sep 12, 2014 at 15:53
  • I'm using postgres for production and sqlite3 for development. See my Gemfile Commented Sep 12, 2014 at 15:55
  • Could it have something to do with the data folder? Commented Sep 12, 2014 at 15:55
  • I'm guessing you're running the rails console from your development machine. LIKE operator is needs that the table collation be case insensitive (utf8_ci for example). If I go to sports-site.herokuapp.com/trailblazers/LaMarcus_Aldridge, the error is missing (aside from the assets error). You need to change the database collation to be case insensitive, or respect case when writing your URL.
    – sjaime
    Commented Sep 12, 2014 at 16:04
  • The error with your assets is because the last route in your routes.rb file is capturing the route for assets. So, if I try sports-site.herokuapp.com/assets/… I get a Missing template error because the router is mapping assets as :team and application-0d909944082bda4534cffeb29f27350e.css as :player
    – sjaime
    Commented Sep 12, 2014 at 16:10
0

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.

1
  • That's what I did. What I posted above is what the log output was when going to the url http://pure-everglades-8286.herokuapp.com/spurs. Commented Sep 9, 2014 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.