14

I've been following along with a tutorial for a Rails app. The tutorial is based on Rails 5 and I am using Rails 5.1.2. Everything works great locally and pushed to heroku with no problems. However, when I went to create an admin user on the production database by running:

$ heroku run rails c

it returns the following error:

/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require': cannot load such file -- rack/handler/c (LoadError) from
/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require' from
/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency' from
/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require' from
/rack-2.0.3/lib/rack/handler.rb:74:in `try_require' from
/rack-2.0.3/lib/rack/handler.rb:16:in `get' from
/rack-2.0.3/lib/rack/server.rb:301:in `server' from
/railties-5.1.3/lib/rails/commands/server/server_command.rb:68:in `print_boot_information' from
/railties-5.1.3/lib/rails/commands/server/server_command.rb:38:in `start' from
/railties-5.1.3/lib/rails/commands/server/server_command.rb:131:in `block in perform' from
/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in `tap' from
/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in `perform' from
/thor-0.20.0/lib/thor/command.rb:27:in `run' from
/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command' from
/thor-0.20.0/lib/thor.rb:387:in `dispatch' from
/railties-5.1.3/lib/rails/command/base.rb:63:in `perform' from
/railties-5.1.3/lib/rails/command.rb:44:in `invoke' from
/railties-5.1.3/lib/rails/commands.rb:16:in  `<top (required)>' from bin/rails:9:in `require' from bin/rails:9:in  `<main>'`

To get around this I can run:

$ heroku run bash
$ rails c

and this allows me to update the production database. While this works and gets me what I need. I want to know why the original command doesn't work. I have searched everywhere for an answer and can't come up with anything that applies to me. I am trying to improve my developing skills and would like to understand why the original problem won't work.

I can add any files anyone needs to see, but I don't even know which ones would be relevant to this problem.

firedev
  • 20,898
  • 20
  • 64
  • 94
Luke Popwell
  • 381
  • 1
  • 3
  • 15
  • Did you post the whole error message? – Stephane Paquet Sep 24 '17 at 18:10
  • 1
    https://devcenter.heroku.com/articles/getting-started-with-rails5#rails-console states that `heroku run rails console` is the right command to access your rails console on heroku. Based on other stackoverflow articles this can be a missing gem or an environment parameter that is not found. – Stephane Paquet Sep 24 '17 at 18:11

2 Answers2

34

You can specify the name of the app in case you have several:

heroku run rails c -a APP_NAME
Cris R
  • 1,339
  • 15
  • 27
0

My understanding is that the heroku run command is provided by the Heroku Command Line Interface (CLI). The CLI doesn't know how to handle the rails c command. However, running heroku run bash will spin up a new dyno and provides access to a Unix shell, where you can run commands (i.e. rails c) much like you're local terminal. For more info see: https://devcenter.heroku.com/articles/how-heroku-works.

Edited to fix mistake: the CLI does know how to handle the rails c command

lgants
  • 3,665
  • 3
  • 22
  • 33
  • 1
    is this a new thing? I literally am watching him run the command `heroku run rails c` as we speak. I know there were some pretty big changes between rails 5 and 5.1 and heroku itself has updated. I'll read through your link and mark it as answered if it talks about this though. thanks – Luke Popwell Sep 24 '17 at 16:18
  • i've review the Heroku docs specific to Rails and it appears that command is supported. Maybe try posting a link to the repository? – lgants Sep 24 '17 at 17:02