如何要求钢轨活动记录在外打工 [英] how to require active record working outside of rails
本文介绍了如何要求钢轨活动记录在外打工的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要需要积极的记录,但我的工作轨道以外(这是为什么:简单的Ruby输入验证库)。我需要需要对整个轨道的宝石,或者我是机?
i need to require active record, but I am working outside of rails (here is why: Simple Ruby Input Validation Library). do I need to require the entire rails gem, or can i be DRYer?
推荐答案
以下是我使用的ActiveRecord Rails的外部:
Here's how I'm using ActiveRecord outside of Rails:
#!/usr/bin/ruby
require 'active_record'
require 'mysql2' # or 'pg' or 'sqlite3'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2', # or 'postgresql' or 'sqlite3'
database: 'DB_NAME',
username: 'DB_USER',
password: 'DB_PASS',
host: 'localhost'
)
# Note that the corresponding table is 'orders'
class Order < ActiveRecord::Base
end
Order.all.each do |o|
puts "o: #{o.inspect}"
end
这篇关于如何要求钢轨活动记录在外打工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文