How to list of all the tables defined for the database when using active record?

Call ActiveRecord::ConnectionAdapters::SchemaStatements#tables. This method is undocumented in the MySQL adapter, but is documented in the PostgreSQL adapter. SQLite/SQLite3 also has the method implemented, but undocumented. >> ActiveRecord::Base.connection.tables => [“accounts”, “assets”, …] See activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21, as well as the implementations here: activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:412 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:615 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:176

ActiveRecord::Base Without Table

This is an approach I have used in the past: In app/models/tableless.rb class Tableless < ActiveRecord::Base def self.columns @columns ||= []; end def self.column(name, sql_type = nil, default = nil, null = true) columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) end # Override the save method to prevent exceptions. def save(validate = true) validate ? valid? … Read more