ActiveRecord::Base.establish_connection in development and production envs

55 views
Skip to first unread message

Nikolay Burlov

unread,
Jul 19, 2011, 2:45:32 AM7/19/11
to Ruby on Rails: Talk
Hi, guys!

Background:
I've resque workers in my application. These workers do several jobs
that associated with DB. In development environment, I've no need to
provide some additional configuration for db, they are use development
database. But then I switching to production env, I set
ActiveRecord::Base.establish_connection with my production DB
parameters.

Problem:
When I'm switch back to development env, I've to comment
ActiveRecord::Base.establish_connection every time. Hope, anybody can
help me and provide a better approach for this situation.

Sincerely,
Nikolay Burlov.

Hassan Schroeder

unread,
Jul 19, 2011, 10:22:18 AM7/19/11
to rubyonra...@googlegroups.com
On Mon, Jul 18, 2011 at 11:45 PM, Nikolay Burlov <koh...@gmail.com> wrote:

> I've resque workers in my application. These workers do several jobs
> that associated with DB. In development environment, I've no need to
> provide some additional configuration for db, they are use development
> database. But then I switching to production env, I set
> ActiveRecord::Base.establish_connection with my production DB
> parameters.
>
> Problem:
> When I'm switch back to development env, I've to comment
> ActiveRecord::Base.establish_connection every time.

Can't you just wrap that in a conditional statement based on the
environment, e.g.

if Rails.env == "production"
ActiveRecord::Base.establish_connection(option_hash)
end

FWIW,
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

koh...@gmail.com

unread,
Jul 19, 2011, 12:26:06 PM7/19/11
to rubyonra...@googlegroups.com
Yeah, I've thought about this. But I wasn't sure that this approach is best.

Thank you!

Sincerely,
Nikolay Burlov.
Reply all
Reply to author
Forward
0 new messages