XIsaax
XIsaax

Reputation: 3

Ruby on Rails website worked locally, routes correct, but on heroku get 404

This is a really strange error that I've encountered. I use ruby on rails. Everything works fine locally (on cloud 9) and I successfully pushed it to Heroku. I have run db:migrate with no error. Nonetheless, I get error "The page you were looking for doesn't exist" and the log says 404. I have checked the files and they have been correctly uploaded. My routes:

  root 'application#index'
  get '/index/:type' => 'application#index'
  get '/index/' => 'application#index'
  get '/benchmark/' => 'application#benchmark'
  get '/benchmark/:type' => 'application#benchmark'
  get '/benchmarkupdate/:name' => 'application#benchmark'
  get '/indexupdate/:name' => 'application#index'

I have files in correct locations. I don't see any problem with routing and it has worked locally.

Heroku Logs:

2017-04-18T03:13:14.455398+00:00 app[web.1]: * Version 3.8.2 (ruby 2.3.4-p301), codename: Sassy Salamander
2017-04-18T03:13:14.455399+00:00 app[web.1]: * Min threads: 5, max threads: 5
2017-04-18T03:13:14.455399+00:00 app[web.1]: * Environment: production
2017-04-18T03:13:15.493228+00:00 app[web.1]: DEPRECATION WARNING: `config.serve_static_files` is deprecated and will be removed in Rails 5.1.
2017-04-18T03:13:15.493241+00:00 app[web.1]: Please use `config.public_file_server.enabled = true` instead.
2017-04-18T03:13:15.493243+00:00 app[web.1]:  (called from block in <top (required)> at /app/config/environments/production.rb:25)
2017-04-18T03:13:16.337785+00:00 app[web.1]: * Listening on tcp://0.0.0.0:49146
2017-04-18T03:13:16.337997+00:00 app[web.1]: Use Ctrl-C to stop
2017-04-18T03:13:16.847301+00:00 heroku[web.1]: State changed from starting to up
2017-04-18T03:13:18.094441+00:00 heroku[router]: at=info method=GET path="/" host=protected-coast-54392.herokuapp.com request_id=3d8c7a3f-3f40-4747-862f-7e70e7c9029e fwd="152.3.34.25" dyno=web.1 connect=1ms service=75ms status=404 bytes=1744 protocol=https

Is there anything else that might cause this problem?

Upvotes: 0

Views: 903

Answers (2)

James Milani
James Milani

Reputation: 1943

Well, for one thing you should not be running WEBrick on production. I'm not positive if this is causing your error, but I'd start there.

Heroku currently recommends puma.

You can install puma by including it in your Gemfile as gem 'puma' and then running bundle install.

In your project directory you will need to include a Procfile that tells your app how to run its web server.

Make sure the Procfile is properly capitalized and checked into git.

It should look something like this:

# <Rails.root>/Procfile
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

Here's an article about WEBrick and one on how to set up puma.

You'll need to re-push to heroku. See if that helps. Cheers.

Upvotes: 0

Steve Carey
Steve Carey

Reputation: 3014

The problem is you haven't set a root route meaning when someone goes to www.example.com without any path after it they are going to the root route. In your routes file add something like

root 'application#index'

or whatever controller and action and the corresponding view that you want people to go to when they first visit your site.

Upvotes: 1

Related Questions