Delayed_job claims database doesn't exist - ruby-on-rails

I've set up delayed_job and it works fine under development.
However, whenever I attempt to run the script under production and run
RAILS_ENV=production script/delayed_job start
I get this:
/Users/simon/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `initialize': FATAL: database "myapp_production" does not exist (PG::Error)
It feels like I'm missing something really basic here (from what I gather it's looking for the production database on my local machine?), but I'm a bit stuck as to where to look and what might cause this problem.
Any pointers would be greatly appreciated.

Well this is pretty much obvious - you are starting your dj in production env, so it tries to connect to the db that is described in the "production" section of config/database.yml. It seems that you haven't created this db yet.
To create this DB run in terminal
RAILS_ENV=production bundle exec rake db:create

Related

Running a heroku database command from pgAdmin III? (Harry's Prelaunchr)

so i've successfully installed Harrys Prelauncher on Heroku (https://github.com/harrystech/prelaunchr)
and to export my collected emails into a csv i need to run this command (bundle exec rake prelaunchr:create_winner_csvs)
is there any way to run that command through pgadmin or some other program?
or is the only way for me to download my heroku database and run the command locally? also how and what would i need to do this?
i'm pretty new to rails and postgresql and would really appreciate if someone could help me out!
Because the rake task creates files locally you can't just run it on heroku via heroku run rake. You can however set up your local database.yml to connect to your heroku postgresql instance and run the rake task locally.
Run heroku pg:credentials to get the required database values.
Fill in the production environment of config/database.yml with the values you obtained from step 1 (for the value of 'database' in the yml file, use dbnmae from step 1)
Test your connection with RAILS_ENV=production rails db. This should drop you into a psql console.
Run the rake task. RAILS_ENV=production bundle exec rake prelaunchr:create_winner_csvs
The files will save locally in lib/assets as indicated by the documentation.
From within the directory of the project you can use
heroku run rake prelaunchr:create_winner_csvs
You should probably create a UI form in to your application.
On click on export CSV, it should run background job on heroku (Using delayed jobs).
heroku run rake prelaunchr:create_winner_csvs
Use send_data ruby method. To send your generated and dumped data file on to your browser.
Download the file on to your local system from running heroku instance.
Hope this will resolve your problem.
Cheers!!!
I ran into this problem recently while developing the Prelaunchr campaign for a client. Assuming you have a local version of your app and are using Postgres Copper in Heroku, you can "pull" your Heroku database down to your local machine, set that as your development database in database.yml, and run the rake task from your local app, which should now have the same database as your heroku version. Here is the command to pull the db (subbing out name_for_database & heroku_app_name with your own):
heroku pg:pull HEROKU_POSTGRESQL_COPPER_URL name_for_database --app heroku_app_name
Make sure to restart your local server to see the new database info populated.

running rake task on 'production' and specifying environment?

I have a host at Linode and am trying to run a Rake task on it, but I get a mySQL error saying it can't connect. It looks like it thinks it is on dev. I did some Googling and saw that I can do something like this:
bundle exec rails c
It loads the dev environment and I can't run User.all giving me an access denied error.
If I run bundle exec rails c RAILS_ENV=production I get the error:
Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
However, if I access it via the web, everything is OK. I was able to run rake db:seed before so I know that there's some way around this.
Accessing mySQL with the production credentials works fine.
Any ideas?
Try this:
rails c production
or, at the beginning:
RAILS_ENV=production rails c
It thinks you're passing RAILS_ENV=production as an argument when you put it at the end.
If you want to run your console in the context of the current bundle in your Gemfile and ensure you're using your Gemset use:
bundle exec rails c production
This works for me. It depends on how your server and all its dependencies are set up:
RAILS_ENV=production bundle exec rails console

Rake error fixed by bundle exec, but deployment not working

I pushed an update to my Rails app production server, and in the update there was a new database migration. I ran rake db:migrate and got the common error seen here. I ran the rake again in bundle exec bash and it was successful. But after restarting my apache server, I'm now getting the 500 Error page. This update worked fine on my localhost, and was mostly this update to the db with supporting changes in the according view and controller/routing.
I don't even know why this error appeared this time, as I have pushed db updates successfully before using only rake. Nonetheless, the rake was successful. The 500 error page only shows on pages that require that specific new ActiveRecord. Any ideas on how to debug?
EDIT: My problem was an extremely simple one. I merely forgot to include the environment with the rake:
bundle exec rake db:migrate RAILS_ENV=production
Unfortunately, it took quite a while to narrow that down, as I couldn't use IRB to check the db entries until I followed these steps.
Did you run rake db:migrate on your server? Also be sure to set the RAILS_ENV flag so your production database is updated:
rake db:migrate RAILS_ENV=production

Rails server does not take in account the production and still used development db

since several days I have this problem:
For a few days it has worked and now I can't do it works again. I setup a rails server on ubuntu with apache-2. I used a git repository to get all new change. After I run
sudo rake db:migrate RAILS_ENV=production
But after have restart apache server I can see that rails use the development db and not the production while before it has used it.
I don't really understand what can cause this. So i really appreciate some help.
Thanks in advance.
Try:
env RAILS_ENV=production rake db:migrate
You can also add the following line to your $HOME/.bash_profile:
export RAILS_ENV=production
I found my problem. In apache sites configuration I had RailsEnv development instead of production.
But now I have another problem: rails does not start due to
* Exception ArgumentError in
PhusionPassenger::Railz::ApplicationSpawner (No association found for
name machines'. Has it been defined yet?) (process 16052):
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:245:in
accepts_nested_attributes_for'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in
each'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in
accepts_nested_attributes_for'
from /home/et1/wip3/sophia/app/models/machines_operatingsystem.rb:2
But I don't understand why.

What's the fastest Ruby on Rails setup for Windows 7?

I have InstantRails installed along with WeBrick and sqlite3.
What exactly do I type in the Windows cmd console to setup a db called 'development' and to get the entire things running?
This is my #&%^# 4th day of installation. I can get everything running on my localhost EXCEPT setup my db. I'm not a programmer so if you have a good url for beginner tutorials that would be great.
Please tell me exactly what I need to type in the cmd console (or what console I need) to make my db hold the information.
I was typing $ sqlite3 db/development.sqlite3 to (boot up?) the db.
Then I typed: CREATE TABLES (code)
Note - I already tried rake db:migrate
Try rake db:migrate (assumimg you have at least 1 migration created ) . The db should be created automatically.

Resources