Get model name

hello

how to get model name for specific table inside code?

i.e.

table: people --> model: person

how to get this?
thanks

On 7/13/07, Mohamed S. [email protected] 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

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
[email protected]

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
[email protected]