Forum: Ruby on Rails DB connection problem in production

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
03e2e7de45b193cac192ae7ea071e5ff?d=identicon&s=25 Arfon Smith (arfon)
on 2009-05-21 17:13
I have a separate DB for one model in my application and in development
mode the connection is working properly, in production however it isn't.

  adapter: mysql
  host: myhost
  username: root
  database: production_db

  adapter: mysql
  host: myhost
  username: root
  database: other_db

The model that connects to the other database is called User but the
table it references in other_db is smf_users so my User.rb looks like

class User < ActiveRecord::Base
  establish_connection "users_#{RAILS_ENV}"
  set_table_name "smf_users"

In production I'm getting this error:

Mysql::Error: Table 'production_db. smf_users' doesn't exist:

Note how it is trying to connect to the wrong database and so isn't
finding the correct table.  As I say, this works in development mode.

Any suggestions?
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2009-05-28 05:37
(Received via mailing list)
From the AWDWR book: "If you pass a symbol to establish_connection,
[...]". Maybe you need to convert your string to a symbol?

establish_connection "users_#{RAILS_ENV}".to_sym


On May 21, 11:13 am, Arfon Smith <>
This topic is locked and can not be replied to.