Four questions about Rails (console, seed file, environment variables, precompiling assets)

June 14, 2013 5.6k views
I used to deploy to Heroku but recently joined DO. I got up and running here with the help of Ryan Bates Railscast on deploying to a VPS, but there are some things he doesn't cover. 1. Can I run the rails console on my ubuntu server? I ran "rails console" in the directory of my app and it gave me a menu of options, such as 'rails new' but there was no option to run the rails console 2. I want to seed my app with some starter data. I can't run 'rake db:seed' (as I would on Heroku) from my app directory. It says no rake file. 3.Environment variables. I need to set Environment Variables for various services that require them (such as email services like Mandrill). How do I set them on DO 4. On Heroku, I used to have to do rake assets:precompile for a Rails app to deploy. This wasn't a requirement on DO. Why (out of curiosity)? (See full trace by running task with --trace)
8 Answers
when you say you're in your "app" directory what does it look like, what subfolders, to make sure it's the right directory...
if you want to set environment variables I'd probably set them globally, like in /etc/profile file. HTH.
in home/username I created a new directory 'app' where the rails app is stored (and where I might store others), so now I have home/username/app. How do I set them in that /etc/profile file?

Would I for example just do this at the bottom of the file?


Do you have any idea about the other questions, how to seed data or run the rails console? running the console on a remote server is very handy, as it lets you alter and view production data etc
Sorry, to provide more information, the directory structure is the following


Inside 'nameofapp' there's three folders 'current' 'releases' and 'shared'. I think these were created by the deploy file that I borrowed from RBates.

When I'm inside current and run "rails console" and "rake db:seed" (there is a rake file), I'm getting the same error

'database configuration does not specify adapter'

However, inside my database yml file I have this

adapter: postgresql
encoding: unicode
database: dodeploy_production
pool: 5
Actually once I cd into the correct folder and run 'rails console' or 'rake db:seed' I'm getting this error

configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

even though the application is actually otherwise working (and saving records).

This is the full database.yml file

adapter: postgresql
encoding: unicode
database: dodeploy_production
pool: 5
host: localhost
username: michael
password: secretpassword
To run rake and rails console I had to specify production environment like this. For example,

RAILS_ENV=production rake db:seed

For environment variables, in bashrc

export LD_ASSUME_KERNEL=2.2.5
@m73mitchell did you ding any solution to this?

I am facing the "database configuration does not specify adapter" error.

Had the same problems.
It seems like unicorn is by default starting in development environment.
Just add -E production in the line UNICORN_OPTS=... in file : /etc/default/unicorn
So that it looks like : UNICORN_OPTS="-D -c $CONFIG_RB -E production"
then : RAILS_ENV=production bundle exec rake assets:precompile
restart unicorn and it should work.

Assuming you're on Rails 4, have you tried:

# Feel free to add this line to e.g. ~/.bashrc so you don't have to type it all the time.
export RAILS_ENV=production

bin/rails console
bin/rake db:version

and so on?

The rails in your path may be different from the one used by your app; bin/rails should get you the right one.

Have another answer? Share your knowledge.