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 ?

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 Pavling 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:

It's one of the Inflector methods... well worth being familiar with them:
http://api.rubyonrails.org/classes/Inflector.html