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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2007/3/3, rv dh <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: 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 ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you Jean-François. I just found out that it is this easy:>> UserArticle.table_name=> "user_article" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---