Rails不使用ActiveRecord

・1 分钟阅读

在本例中,我将新记录保存到MySQL数据库的employees表中。

require"rubygems"
require_gem"activerecord"
ActiveRecord::Base.establish_connection (
 :adapter =>"mysql",
 :host =>"localhost",
 :username =>"root",
 :database =>"HumanResources")
class Employee < ActiveRecord::Base
end
employee = Employee.new
employee.first_name ="Fred"
employee.last_name ="Flinstone"
employee.save
gem install activerecord

很多时候,我写的Ruby代码与网页, Rails无关,能够在没有Rails的情况下使用ActiveRecord感觉非常棒。

讨论
凉爽拍拍 profile image