问题描述
我一直在试图使用mysql和活动记录的Ruby脚本,但我得到了以下信息:过时的mysql的宝石。升级到2.8.1或更高版本。在您的Gemfile:创业板MySQL的,2.8.1。或者使用宝石'mysql2(RuntimeError)。之前,我得到一个消息,关于创业板mysql2失踪,但后来我检查了在活动记录的连接适配器源$ C $ C,只见它需要哪些我没有安装mysql的宝石。
这是我的脚本:
需要'rubygems的'
需要'active_record
需要'机械化'
需要'引入nokogiri
需要'active_record
需要'mysql2
创业板mysql2
的ActiveRecord :: Base.establish_connection({
:适配器=> MySQL的,
:主机=> 本地主机,
:用户名=> 根,
:密码=> ,
:数据库=> rainalytics})
的ActiveRecord :: Schema.define(:版本=> 20110320035328)办
CREATE_TABLEscore_logs:力=>真做| T |
t.integerblog_posts
t.integer特色
结束
CREATE_TABLE用户,:力=>真做| T |
t.datetimecreated_at
t.datetime的updated_at
结束
结束
类用户的LT;的ActiveRecord :: Base的
的has_many:score_logs
结束
类ScoreLog<的ActiveRecord :: Base的
belongs_to的:用户
结束
我不是用'需要'mysql2'或'宝石'mysql2'部分,它似乎是工作的罚款,我也有另外的{}内的ActiveRecord :: Base的块
希望这可以帮助别人的未来:)的
这是我使用
红宝石1.9.2p318(2012-02-14改版34678)的x86_64-darwin11.2.0]
Rails的3.1.0
规定的RubyGems
要求active_record
的ActiveRecord :: Base.establish_connection({
:适配器=> mysql2
:主机=> 本地主机,
:用户名=> 根,
:密码=> 根,
:数据库=> cybercellar})
类区<的ActiveRecord :: Base的
结束
区= Zone.all
打印区域
然后,我浏览到我的应用程序文件夹,运行
文件
I've been trying to use mysql and active record on a ruby script but I'm getting the following message: Outdated mysql gem. Upgrade to 2.8.1 or later. In your Gemfile: gem 'mysql', '2.8.1'. Or use gem 'mysql2' (RuntimeError). Before I was getting a message about gem 'mysql2' missing but then i checked the source code on the connection adapters in active record and saw that it require mysql gem which i didnt have installed.
this is my script:
require 'rubygems'
require 'active_record'
require 'mechanize'
require 'nokogiri'
require 'active_record'
require 'mysql2'
gem 'mysql2'
ActiveRecord::Base.establish_connection ({
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "",
:database => "rainalytics"})
ActiveRecord::Schema.define(:version => 20110320035328) do
create_table "score_logs", :force => true do |t|
t.integer "blog_posts"
t.integer "featured"
end
create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
end
end
class User < ActiveRecord::Base
has_many :score_logs
end
class ScoreLog < ActiveRecord::Base
belongs_to :user
end
Im not using the 'require 'mysql2' or 'gem 'mysql2' parts, and it seems to be working fine, I also have additional {} inside the ActiveRecord::Base block
hope this can help someone in future :)
This is what I use
ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-darwin11.2.0]
Rails 3.1.0
require "rubygems"
require "active_record"
ActiveRecord::Base.establish_connection ({
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "root",
:database => "cybercellar"})
class Zone < ActiveRecord::Base
end
zone = Zone.all
print zone
then I navigate to my app folder and run the file
这篇关于在使用Ruby脚本活动记录和mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!