# How to pass model names?

**URL:** <https://www.ruby-forum.com/t/how-to-pass-model-names/187730>\
**Category:** Rails\
**Created:** [April 28, 2010, 12:23pm UTC](https://www.ruby-forum.com/t/how-to-pass-model-names/187730 "2010-04-28T12:23:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 12:23pm UTC](https://www.ruby-forum.com/t/how-to-pass-model-names/187730/1 "2010-04-28T12:23:34Z")

</div>

How to pass model names?

The scenario is that i have written a function in application\_hepler.rb  
as like…

def all\_record\_ids(model\_name)  
all\_records = model\_name.all.find\_all {  
|record| record.status == “ACTIVE”  
}  
end

I am calling this function as like [all\_record\_ids(“Employee”)] but  
instead of getting result i am getting error as [ “undefined method  
`all’ for “Employee”:String” ]

So what is wrong here … ? Can you guys light me up some direction ?

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 12:30pm UTC](https://www.ruby-forum.com/t/how-to-pass-model-names/187730/2 "2010-04-28T12:30:19Z")

</div>

On 28 April 2010 11:23, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How to pass model names?

def all\_record\_ids(model\_name)  
all\_records = model\_name.constantize.all.find\_all {  
|record| record.status == “ACTIVE”  
}  
end

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 12:45pm UTC](https://www.ruby-forum.com/t/how-to-pass-model-names/187730/3 "2010-04-28T12:45:58Z")

</div>

Michael P. wrote:

> def all\_record\_ids(model\_name)  
> ï¿½all\_records = model\_name.constantize.all.find\_all {  
> ï¿½ ï¿½|record| record.status == “ACTIVE”  
> ï¿½}  
> end

Thanks dude… It worked like a charm… i was not aware of this keyword…  
🙂

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 12:50pm UTC](https://www.ruby-forum.com/t/how-to-pass-model-names/187730/4 "2010-04-28T12:50:14Z")

</div>

On 28 April 2010 11:45, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks dude… It worked like a charm… i was not aware of this keyword…

It’s one of the Inflector methods… well worth being familiar with  
them:  
[http://api.rubyonrails.org/classes/Inflector.html](http://api.rubyonrails.org/classes/Inflector.html)
