title: Dynamically get Rails DB queries
body: <p>Is there a way to dynamically get a db result in rails? FOr example, I have all of cities indexed with an id. I want to sent the id to the view given a city name, like this Javascript method (I know this doesn't work...)</p>
  
  <pre><code>function getCityId (city) {
    return &lt;%= City.where(name =&gt; city) %&gt;
  end
  </code></pre>
  
  <p>I'm aware there are solutions using ajax, the problem is ajax, as far as I've seen, only works with link_to and form_for, as only these accept the remote: true option. I've though about making an invisible link and initiating a "click()" upon certain conditions, like "keydown" or something, but this is obviously very messy and gross. The other option is to hardcode the ajax, as in the answer cited below, but this is tedious and cluttered.</p>
  
  <p>Is there a way to perform ajax using a simply url_for or comparable helper, or some other way to dynamically get db info? (In know there is a similar question <a href="https://stackoverflow.com/questions/5268829/remote-true-with-url-for-how-does-one-do-this">here</a>, but I thought maybe if I asked a more specific question there could be another workaround.)</p>