Activerecord abstrat class
Ruby
code posted
by
Iain McNulty
created at 14 Jul 21:35, updated at 15 Jul 06:41
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
require 'sqlite3' require 'active_record' class Alcoholic < ActiveRecord::Base self.abstract_class = true establish_connection adapter: "sqlite3", database: "../../db/brewing.sqlite" def self.create_the_tables self.descendants.each do |a| a.connection.create_table(a.to_s.downcase.pluralize) end end end class Beer < Alcoholic end class Cider < Alcoholic end |
404 Bytes in 2 ms with coderay