Created
November 20, 2012 06:57
-
-
Save dchentech/4116488 to your computer and use it in GitHub Desktop.
在Rails外面使用ActiveRecord,并直接声明全部model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.establish_connection(YAML.load_file('./config/database.yml')['production']) | |
ActiveRecord::Base.connection.execute("show tables;").to_a.flatten.map do |table_name| | |
eval "class #{table_name.camelcase} < ActiveRecord::Base; self.table_name = :#{table_name}; end" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment