ActiveRecord属于Rails的子框架,我们可以在Rails外使用它
process_orders_nightly.rb:
[code]
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "nightlybatch",
:password => "secret",
:database => "web_orders"
)
class Order < ActiveRecord::Base
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
Order.find(:all).each do |o|
puts "Processing order number #{o.id}"
'./sendorder -c #{o.customer_id} \
-p #{o.product_id} \
-q #{o.quantity}'
end
[/code]
process_orders_nightly.rb:
[code]
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "nightlybatch",
:password => "secret",
:database => "web_orders"
)
class Order < ActiveRecord::Base
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
Order.find(:all).each do |o|
puts "Processing order number #{o.id}"
'./sendorder -c #{o.customer_id} \
-p #{o.product_id} \
-q #{o.quantity}'
end
[/code]