Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run rails console in Heroku? Rails 5.1 and postgresql

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:

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

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.

like image 781
Luke Popwell Avatar asked Sep 24 '17 15:09

Luke Popwell


People also ask

Which type of database Cannot be used to deploy your Rails app to Heroku?

So, the reason why you cannot use SQLite on Heroku is because SQLite stores all database information in a file on disk, and because Heroku will delete the files on your disk, this won't work.

How do I start rails console?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .

Does Heroku support rails 7?

Ruby on Rails is a popular web framework written in Ruby. This guide covers using Rails 7 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for Rails 6. x or Rails 5.


1 Answers

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

heroku run rails c -a APP_NAME
like image 166
Cris R Avatar answered Oct 21 '22 08:10

Cris R