11155
(-- --)
April 28, 2010, 10:23am
1
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
11155
(-- --)
April 28, 2010, 10:45am
3
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..
It's one of the Inflector methods... well worth being familiar with them:
http://api.rubyonrails.org/classes/Inflector.html