Why can't I access my db rail application after making a new connection to wordpress db manually?

I have a rails 4.2 application with a postgres database running. I have a requirement to connect to other databases (word_press_sites) on request.

I tried the code below in the rails console:

ActiveRecord::Base.establish_connection(
  adapter:  "mysql2",
  host:     ENV["HOST"],
  username: ENV["USERNAME"],
  password: ENV["PASSWORD"],
  database: ENV["DB_NAME"]
)

above code results, There is no error related to word_press database_tables.

1) If I try to access the table by calling User.all in my rails db application, I cannot get access that throws an error.

+6
source share
1 answer

After opening the rail console, you can check

ActiveRecord::Base.connection.current_database

db. script,

ActiveRecord::Base.establish_connection(
    adapter:  "mysql2",
    host:     ENV["HOST"],
    username: ENV["USERNAME"],
    password: ENV["PASSWORD"],
    database: ENV["DB_NAME"]
)

ActiveRecord::Base.connection.current_database

ActiveRecord , Wordpress, rails

app db,

ActiveRecord::Base.remove_connection( ActiveRecord::Base)

,

+7

All Articles