Lets say I wish to make a page that can query the desired object with type(string) and id(int).
/query?type=people&id=1
would fetch me
Person.find(1)
whereas
/query?type=cities&id=123
would fetch me
City.find(123)
However, I have problems as to how to translate strings into the desired model class.
The only way I can think of is
case params[:type]
when 'people'
@object = Person.find(params[:id])
when 'cities'
@object = City.find(params[:id])
end
However, this method will be quite problematic if I have more types of models.
Is there a better way?
Thank you in advance,