# Get model name

**URL:** <https://www.ruby-forum.com/t/get-model-name/109280>\
**Category:** Rails\
**Created:** [July 13, 2007, 2:25am UTC](https://www.ruby-forum.com/t/get-model-name/109280 "2007-07-13T02:25:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [July 13, 2007, 2:25am UTC](https://www.ruby-forum.com/t/get-model-name/109280/1 "2007-07-13T02:25:15Z")

</div>

hello

how to get model name for specific table inside code?

i.e.

table: people --\> model: person

how to get this?  
thanks

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [July 13, 2007, 2:32am UTC](https://www.ruby-forum.com/t/get-model-name/109280/2 "2007-07-13T02:32:47Z")

</div>

On 7/13/07, Mohamed S. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [July 13, 2007, 4:20am UTC](https://www.ruby-forum.com/t/get-model-name/109280/3 "2007-07-13T04:20:57Z")

</div>

On Jul 12, 2007, at 8:25 PM, Mohamed S. wrote:

> thanks  
> Don’t ask that here.  
> Ask there =\> [http://nubyonrails.com/tools/pluralize](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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [July 13, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/get-model-name/109280/4 "2007-07-13T14:10:43Z")

</div>

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](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](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid
