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 3851892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:13:58+00:00 2026-05-19T17:13:58+00:00

There is another question on stackoverflow with this title. This is the link to

  • 0

There is another question on stackoverflow with this title. This is the link to that. My question is a little different but almost on the same line

I work with a database that has multiple users each having a unique set of privileges to the database. Hence I can’t hard code the database login details in the database.yml. Instead I want to create a html form which collects the login credentials. I understand that database.yml can be written in the erb way from this link. But by the time, my index.html(the page in which I have written my form) is shown, the attempt to establish connection is done and it is throwing an error saying nil is provided for username and password. Please let me know how to approach this problem.

I am new to rails, so please ask me if I didn’t provide enough information. Thanks in advance

  • 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-19T17:13:59+00:00Added an answer on May 19, 2026 at 5:13 pm

    Use ActiveRecord::ConnectionHandling.establish_connection function call to connect to your database. You should be able to establish a connection with a different user even on every page if you would like, or look up the database credentials in a User model.

    If you are doing this, you might consider subclassing ActiveRecord::Base and overriding the connection call, which would then be used by every model to connect to the database.

    If you want to completely avoid a connection to the database before you explicitly set up the credentials through your application, then you probably want to initialize Rails without loading all of the ActiveRecord specific stuff. In that case, you will need to remove ActiveRecord from the initialization of Rails by putting this line in your config/environment.rb, within the Rails::Initializer.run do |config| block:

    config.frameworks -= [ :active_record ]
    

    Then you will need to load all of the ActiveRecord specific things once you have the credentials.

    Alternatively, you can override Rails::Initialize::initialize_database which is where the actual database connection is being used by putting this in your environment.rb before the Rails::Initializer.run call:

    module Rails
      class Initializer
        def initialize_database
          nil
        end
      end
    end
    

    Prior to rails 4.x you would use ActiveRecord::Base.establish_connection, which is now deprecated.

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

Sidebar

Related Questions

There is another recent Project Euler question but I think this is a bit
Is there a way to link to another View that displays search results without
I posted this digital logic diagram as an answer to another stackoverflow question .
I posted this question here before but there were no responses. I may have
Inspired by another question asking about the missing Zip function: Why is there no
An extenstion of this question: https://stackoverflow.com/questions/50335/ok-cancel-or-cancel-ok Where should the APPLY button go (clicking the
According to this stackoverflow post , there is a limit on Mac OS X
Something that has been bugging me since I read an answer on another stackoverflow
I saw from another question here : Determine iPhone user's country that it is
Is there another way to render graphics in C# beyond GDI+ and XNA ?

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.