How do I list all the tables in a database?

Hi,
how do I list all the tables in a database?
I’ve googled for a time but din’t found this information.
Is there an object to the database?

tkns in advance.

Hi P. Pantouffe,

how do I list all the tables in a database?

with : ActiveRecord::Base.connection.tables

– Jean-François.


À la renverse.

Thank u!
I have another one :). How can i get a list with all the classes in the
application after i wrote several models. ?

P. Pantouffe :

I have another one :). How can i get a list with all the classes in the
application after i wrote several models. ?

In production mode, for AR:B-based models :

ActiveRecord::Base.send(:subclasses)

but I’m not so sure…

– Jean-François.


À la renverse.

the otput for
<%= ActiveRecord::Base.send(:subclasses).to_s %> is
CGI::Session::ActiveRecordStore::SessionMenuelement
i am in development, should these be the cause?

P. Pantouffe wrote:

Thank u!
I have another one :). How can i get a list with all the classes in the
application after i wrote several models. ?

This code, derived from annotate plugin
(http://svn.pragprog.com/Public/plugins/annotate_models/), processes all
models contained in app/models/

def model_files
Dir.chdir(MODEL_DIR) do
models = Dir["**/*.rb"]
end
end

def process_model_files
model_files.each do |m|
class_name = m.sub(/.rb$/,’’).camelize
klass = class_name.split(’::’).inject(Object){ |klass,part|
klass.const_get(part) } rescue nil
if klass && klass < ActiveRecord::Base && ! klass.abstract_class?
#your code
end
end
end

regards
Massimo
http://www.addsw.it

Not exactly what you are asking for, but might be useful:
http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/AnnotateModels.rdoc

it annotates your models

On Jan 25, 8:03 am, “P. Pantouffe” [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs