2015-03-31 72 views
0

我試圖與MySQL數據庫conncet並獲得從該特定數據庫中的數據,但它正在崛起的錯誤..,修復它PLZ寶石2.0。與ActiveRecord的兼容性問題4.1.2

代碼是:

require 'rubygems' 
#require 'mysql' 
require 'active_record' 


ActiveRecord::Base.establish_connection(
    { 
    :adapter => 'mysql', 
    :host => 'localhost', 
    :database => 'spyware', 
    :user => 'root', 
    :password => 'sqlpass' 
    } 
) 

class Definition<ActiveRecord::Base 
end 

defni = Definition.Find(:all) 

defni.each do |row| 

    print "\n\n".row.name 
end 

我得到的錯誤是::

ruby dbconnect.rb 
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.1.2/lib/active_record/connection_adapters/connection_specification.rb:190:in `rescue in spec': Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError) 
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.1.2/lib/active_record/connection_adapters/connection_specification.rb:187:in `spec' 
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.1.2/lib/active_record/connection_handling.rb:50:in `establish_connection' 
    from dbconnect.rb:6:in `<main>' 
>Exit code: 1 

我使用的2.0.14和MySQL版本的寶石版本2.8.1 86

回答

0

Rails已經爲您提供了答案:將gem 'mysql'添加到您的Gemfile(並確保其版本處於ActiveRecord所要求的最低限度)。 閱讀錯誤日誌是個好主意! ;)

+0

已經添加,但它給 – 2015-03-31 12:11:55

+0

你運行'捆綁安裝'來安裝gemfile中的所有寶石? – 2015-03-31 12:14:03

+0

你能否清楚的解釋一下如何運行bundle install和els plz – 2015-04-02 05:53:18