Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 549473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:11:18+00:00 2026-05-13T11:11:18+00:00

I have a Model (MessageImporter) that connects to a different Database than the other

  • 0

I have a Model (MessageImporter) that connects to a different Database than the other models using self.establish_connection. Everything works fine when I pass the connection info hardcoded. Now I need the connection to depend on the current environment. So I added the info to my application_config.yml (it’s a simple nifty_config). I got stuck at how to pass the connection info to self.establish_connection.

Here’s my current code:

class MessageImporter < ActiveRecord::Base
  self.establish_connection lambda {{
    :adapter => APP_CONFIG[:external_messages][:adapter],
    :host => APP_CONFIG[:external_messages][:host],
    :database => APP_CONFIG[:external_messages][:database],
    :username => APP_CONFIG[:external_messages][:username],
    :password => APP_CONFIG[:external_messages][:password]
  }}

# […]

I get an undefined method 'symbolize_keys' for #<Proc:0x2564224>-. Error I also tried it without the lambda, but that does not work either and I get an even weirder error:

Please install the  adapter: `gem install activerecord--adapter` (no such file to load -- active_record/connection_adapters/_adapter)

Or is there a better/Rails-ish way to set a different db-connection for individual models?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:11:18+00:00Added an answer on May 13, 2026 at 11:11 am

    Little different approach and it works:

    Adding the connection info to the regular database.yml:

    development:
      adapter: mysql
      encoding: utf8
      reconnect: false
      database: […]
      pool: 5
      username: root
      password:
      socket: /tmp/mysql.sock
    
      message_import:
        adapter: mysql
        encoding: utf8
        username: […]
        password: […]
        database: […]
        host: […]
    

    Note the nesting! message_import ist nested beneath development.

    Within the message_importer.rb:

    class MessageImporter < ActiveRecord::Base
      establish_connection configurations[RAILS_ENV]['message_import'] 
    

    Still wondering why my first approach didn’t work but this does just as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.