2

I am using MySQL and ruby 1.8.6. I want to connect to MySQL so for that I am using active record gem. My code is

def initialize

    @db_adapter  = "mysql2"
    @db_host     = "localhost"
    @db_database = "database_name"
    @db_user     = "root"
    @db_password = "root123"
    con = nil

end

def database_connection
           con = ActiveRecord::Base.establish_connection(  
              :adapter  => $db_adapter,  
              :host     => $db_host,  
              :database => $db_database,
              :user     => $db_user,
              :password => $db_password  
           )

           return con
end

but when i am tring to connect it's giving me this error

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection': Please install the  adapter: `gem install activerecord--adapter` (no such file to load -- active_record/connection_adapters/_adapter) (RuntimeError)
    from /cmf/samnew/build/Controller/databaseConnection.rb:32:in `database_connection'
    from controller.rb:23
2
  • 1
    run gem install activerecord-adapter and try again Commented Sep 20, 2012 at 6:57
  • 1
    Note that @instance_variables aren't the same thing at all as $global_variables. Commented Sep 28, 2012 at 20:51

2 Answers 2

3

The error shows the activerecord--adapter gem is not installed. You can install the gem using the command

gem install activerecord--adapter.
Sign up to request clarification or add additional context in comments.

Comments

0

Try

con = ActiveRecord::Base.establish_connection(  

        :adapter  => @db_adapter,  

        :host     => @db_host,  

        :database => @db_database,

        :user     => @db_user,

        :password => @db_password  

)

1 Comment

Print your variable $db_adapter in database_connection function, I think that you need variable @db_adapter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.