timpone
timpone

Reputation: 19979

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?

Upvotes: 24

Views: 37251

Answers (3)

Mark Locklear
Mark Locklear

Reputation: 5355

This works for me. It depends on how your server and all its dependencies are set up:

RAILS_ENV=production bundle exec rails console

Upvotes: 0

Hunter
Hunter

Reputation: 1687

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 

Upvotes: 2

Nick Colgan
Nick Colgan

Reputation: 5518

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.

Upvotes: 53

Related Questions