Search code examples
ruby-on-railsactiverecordproduction-environment

Access Rails ActiveRecord db in production mode


I've just deployed my first app to production. It's a simple front end for managing a DB, and the real action for the app happens in a script I placed in app/ called validation_script.rb. It accesses elements in the DB using ActiveRecord and performs actions based on their values. When I was developing, I would test the script by:

rails runner app/validation_script.rb

This ran without any problems on my local machine. But now that I have pushed this onto the hosting server and into production mode, running that same command on the server doesn't access the elements in the ActiveRecord DB. I set my environment in environment.rb to ENV['RAILS_ENV'] ||= 'production'. Are there any other settings I'm missing in order to connect to the production DB?


Solution

  • Try this:

    rails runner -e production app/validation_script.rb