Search code examples
ruby-on-railscapistrano

running rails console in Capistrano deployed app


I've deployed a Rails app to AWS using Capistrano, and now I'm trying to start Rails console, but can't. If I go into home/user/app-name/current/ and try running rails c I just get instructions on how to use the rails command.

Alternatively, I need to run a command, specifically a Searchkick command ClassName.reindex is there a way I'm missing to do this without opening the console?


Solution

  • rails c is probably failing due to the fact that you are missing bin/rails in your deployed app. See this answer for a fix: Rails 4 doesn't detect application after capistrano deployment

    Once you get bin/rails working, you can run a command without using the console like this:

    bundle exec rails runner ClassName.reindex
    

    The runner Rails command loads your app and evaluates whatever Ruby code you supply.

    Depending on how you've done your deployment, you may need to explicitly specify the environment, like this:

    bundle exec rails runner -e production ClassName.reindex