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"`
Adam Zerner
  • 17,797
  • 15
  • 90
  • 156

3 Answers3

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!

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • 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. – Adam Zerner Sep 10 '14 at 14:04
  • Does it have something to do with the `data` folder I have? – Adam Zerner Sep 12 '14 at 15:52
  • It shouldn't have any bearing on the issue - what issues do you think it would cause? – Richard Peck Sep 13 '14 at 08: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 Feb 07 '16 at 14:12
1

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.

sjaime
  • 1,480
  • 9
  • 16
  • See the code on github - https://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. – Adam Zerner Sep 12 '14 at 15:53
  • I'm using postgres for production and sqlite3 for development. See my [Gemfile](https://github.com/adamzerner/sports_site/blob/master/Gemfile) – Adam Zerner Sep 12 '14 at 15:55
  • Could it have something to do with the [data folder](https://github.com/adamzerner/sports_site/tree/master/data)? – Adam Zerner Sep 12 '14 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 http://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 Sep 12 '14 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 http://sports-site.herokuapp.com/assets/application-0d909944082bda4534cffeb29f27350e.css I get a `Missing template error` because the router is mapping assets as :team and application-0d909944082bda4534cffeb29f27350e.css as :player – sjaime Sep 12 '14 at 16:10
  • Also, your app shouldn't break if @player is nil. You could just easily check in your view `if @player.nil?` and don't output the `

    ` tag if it it's indeed `nil`.

    – sjaime Sep 12 '14 at 16:19
  • I [changed the routes](https://github.com/adamzerner/sports_site/blob/master/config/routes.rb) but they're still not loading. Also, do you know of an easy way to fix the table collation issue? I don't know anything about that stuff. If not, I could just fix the urls. – Adam Zerner Sep 12 '14 at 16:51
  • It seems you're using webrick as your server (which is not a good option for a production server). Either you set `config.serve_static_assets = true` , which will make webrick serve the assets, or you use a webserver like Apache or Nginx to serve your static assets (that should be the way to go for a production site, although I've never deployed to heroku so don't really know what your options are). As for the collation issue, you could issue an `ALTER TABLE ...`command from the psql prompt, or you can check this question: http://stackoverflow.com/q/5090858/4035338 – sjaime Sep 12 '14 at 17:03
  • Sorry, I'm familiar with MySQL, not Postgress. Apparently there is no case insensitive collation for Postgress, but you could use `ilike` instead of `like` in your query. – sjaime Sep 12 '14 at 17:06
  • Webrick is the local server (the one that runs when I run `rails s`). But I don't think it's the one that heroku uses. Are you sure I should set `config.serve_static_assets = true`? (it seems you recommended that thinking that webrick is the production server that heroku is using) – Adam Zerner Sep 12 '14 at 17:33
  • https://devcenter.heroku.com/articles/ruby-default-web-server If you inspect the response headers of your site with your browser web inspector, you'll see that the header it returns shows the server signature as webrick. It seems to me that you're not using Apache or Nginx since there is no route to your assets (you get a 404 error). You should only set config.serve_static_assets to true if you are not using a server that is capable of handling static content. – sjaime Sep 12 '14 at 17:42
  • Setting `config.serve_static_assets = true` worked, thanks. So does that mean webrick isn't capable of handling static content? – Adam Zerner Sep 12 '14 at 17:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/61134/discussion-between-sjaime-and-adam-zerner). – sjaime Sep 12 '14 at 18:53
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.

Joel
  • 4,503
  • 1
  • 27
  • 41
  • 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`. – Adam Zerner Sep 09 '14 at 23:14