Get model name


#1

hello

how to get model name for specific table inside code?

i.e.

table: people --> model: person

how to get this?
thanks


#2

On 7/13/07, Mohamed S. removed_email_address@domain.invalid wrote:

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


#3

On Jul 12, 2007, at 8:25 PM, Mohamed S. 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 B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#4

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 B. wrote:

On Jul 12, 2007, at 8:25 PM, Mohamed S. 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 B. http://agileconsultingllc.com
removed_email_address@domain.invalid