How to pass model names?

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 ?

On 28 April 2010 11:23, Hemant B. [email protected] 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

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…
:slight_smile:

On 28 April 2010 11:45, Hemant B. [email protected] 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