In Rails, how do I query my database from JavaScript so that I can fill in a textbox?

I have a view that uses the select method in Ruby on Rails to return the following code:

    <select class="form-control" name="xyz" id="food_id">
    <option value="1">Peach</option>
    <option value="2">Apple</option>
    <option value="3">Orange</option>
    </select>

To pass this information over to the JavaScript file, I am basically using a link_to method in my view, such as the following:

<%= link_to "Import text", "#/", :onclick => "fillTextBox()" %>

In the JS file, how can I basically get the name and description of whatever value is selected in the dropdown? This is as far as I’ve gotten before I got confused:

function fillTextBox(){
    var dropdown = document.getElementById('food_id');
    var foodID = dropdown[dropdown.selectedIndex].value;
}

I need to do something like:

var foodName = Food.find(foodID).name;
var foodDescription = Food.find(foodID).description;

Is this possible? The rest of the JS function would basically fill in a textbox using foodName and foodDescription, but I first need to be able to query the database for this information in the first place.


Source: stackoverflow-javascript