Rails的script如何引入Rails的環境?

常常需要開發一些script,需要引用Rails的model

ENV['RAILS_ENV'] ||= 'production'
require File.dirname(__FILE__) + "/../config/environment"


還有一些需要直接查數據的操作

可以使用Mysql2

require 'mysql2'

client = Mysql2::Client.new(:host => "localhost", :username => "root")
client.query('use xxxxx')
fields = client.query("show fields from xxx_xxxx").each do |row|
  row["Field"]
end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章