hello how to get model name for specific table inside code? i.e. table: people --> model: person how to get this? thanks -- 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 -~----------~----~----~----~------~----~------~--~---
On 7/13/07, Mohamed Saeed <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > hello > > how to get model name for specific table inside code? > > i.e. > > table: people --> model: person > > how to get this? > thanks > > --If you have an instance of person "#{@person.class}".downcase will get you a string in lowercase of the class name. HTH Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 12, 2007, at 8:25 PM, Mohamed Saeed wrote:> > hello > > how to get model name for specific table inside code? > > i.e. > > table: people --> model: person > > how to get this? > thanksDon''t ask that here. Ask there => http://nubyonrails.com/tools/pluralize You want: "people".classify => "Person" You might also want: "people".classify.constantize => Person constantize gives you the class, not a String. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Of course,
all of these rely on using the default table name,
if out of legacy you have a class
class CrazyClass
    set_table_name :this_is_crazy
end
this wouldn''t work.
Rob Biedenharn wrote:> On Jul 12, 2007, at 8:25 PM, Mohamed Saeed wrote:
> 
>> thanks
> Don''t ask that here.
>    Ask there =>  http://nubyonrails.com/tools/pluralize
> 
> You want:
>    "people".classify => "Person"
> You might also want:
>   "people".classify.constantize => Person
> 
> constantize gives you the class, not a String.
> 
> -Rob
> 
> Rob Biedenharn    http://agileconsultingllc.com
> Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
-- 
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
-~----------~----~----~----~------~----~------~--~---