Table name of an object

Hello,

how can I find out the table name of an object?

For example I have the object ua of the class UserArticle:
ua = UserArticle.find(1)

How can I find out it is saved in the table user_articles?

2007/3/3, rv dh [email protected]:

Hi,

how can I find out the table name of an object?

For example I have the object ua of the class UserArticle:
ua = UserArticle.find(1)

How can I find out it is saved in the table user_articles?

With AR::B.table_name :

UserArticle.table_name

=> “user_articles”

If you have the name of the class in a string and you’re
following Rails conventions (and assuming you haven’t a prefix
or a suffix), then you can write :

‘UserArticle’.tableize

=> “user_articles”

– Jean-François.


Ruby ( http://www.rubyfrance.org ) on Rails ( http://www.railsfrance.org
)

Thank you Jean-François. I just found out that it is this easy:

UserArticle.table_name
=> “user_article”

rv dh wrote:

Thank you Jean-François. I just found out that it is this easy:

UserArticle.table_name
=> “user_article”

This is not what I initially asked for, of course. I meant to say it is
as easy as this:

ua = UserArticle.find(1)
ua.class.to_s.tableize