0

This is my first question here so I hope I'm within the rules.

I've just completed Chapter 7 of the Michale Hartl Rails Tutorial. My sample_app works locally and has worked on Heroku until this point.

At the end of the chapter is a section called "7.5 Professional-grade deployment." This switches the production environment to SSL and the Puma web server.

The following code shows the changes I've made as part of this section, which led to the app not working on Heroku.

config/environments/production.rb - uncommented this line to enable SSL

config.force_ssl = true

Gemfile - added Puma

group :production do
  gem 'pg', '0.17.1'
  gem 'rails_12factor', '0.0.2'
  gem 'puma', '2.11.1'
end

config/puma.rb - I copied this direct from the Heroku site after copying from the Rails Tutorial pdf failed

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

Created the Procfile

web: bundle exec puma -C config/puma.rb

After committing, pushing to Heroku and migrating the database, I get a page that says "Application error."

This is the output of heroku logs:

2015-05-14T11:55:46.257652+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2015-05-14T11:55:48.438024+00:00 app[web.1]: ...                               ^
2015-05-14T11:55:48.438026+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/configuration.rb:179:in `_load_from'
2015-05-14T11:55:48.438029+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/configuration.rb:40:in `load'
2015-05-14T11:55:48.438035+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/bin/puma:10:in `<top (required)>'
2015-05-14T11:55:48.438034+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/cli.rb:453:in `run'
2015-05-14T11:55:48.438017+00:00 app[web.1]: /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/configuration.rb:179:in `instance_eval': config/puma.rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input (SyntaxError)
2015-05-14T11:55:48.438040+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/bin/puma:23:in `<main>'
2015-05-14T11:55:48.438031+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/cli.rb:308:in `parse_options'
2015-05-14T11:55:48.438039+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/bin/puma:23:in `load'
2015-05-14T11:55:48.437914+00:00 app[web.1]: config/puma.rb:1: warning: encountered \r in middle of line, treated as a mere space
threads_count = Integer(ENV['MAX_THREADS']......NCURRENCY'] || 2)
2015-05-14T11:55:49.211862+00:00 heroku[web.1]: Process exited with status 1
2015-05-14T11:55:49.223366+00:00 heroku[web.1]: State changed from starting to crashed

I get the impression from "syntax error" that there's something wrong with my config/puma.rb file, but I can't work out what.

I tried specifying the Ruby version number, but that didn't help.

What's wrong with this and how can I put it right?

Neil Wheatley
  • 71
  • 1
  • 10
  • Could be an issue with copying text from website to editor adding some extra whitespaces as described in http://stackoverflow.com/questions/18946105/rails-4-syntax-error-unexpected-tidentifier-expecting-end-of-input Try typing out the content of `config/puma.rb` from scratch. – Prakash Murthy May 14 '15 at 14:06
  • Thanks, I did re-type all the spaces and line breaks as I've had that issue before. But I think I'll now try to re-type the whole doc. (I started using Atom recently and haven't had problems like that with it so far.) – Neil Wheatley May 14 '15 at 15:10
  • Tried re-typing, didn't work :( – Neil Wheatley May 14 '15 at 15:23

2 Answers2

0

Had exactly the same problem and spend some serious churn on this. There was duplicate code in the file config/puma.rb Somehow the code was added at the bottom of the file.

I copied over the code exactly as it was in the bitbucket repository. Also, I have learned it is best to select raw when copying code to prevent extra spaces or copying errors.

Laurie
  • 162
  • 1
  • 11
-1

Prakash Murthy pretty much answered this for me - thanks.

At first I tried to re-type the contents of the puma.rb - it didn't work.

Then I decided to try deleting puma.rb altogether, and typing it from scratch in a new file. Weirdly, it worked!

My text editor is Atom. Hope this doesn't happen again.

Neil Wheatley
  • 71
  • 1
  • 10