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