I have a database named Staff in mongoDB, which includes a collection called records. Within this collection, there is a field named workgroup that contains entries such as "management", "union", "support staff", and more.
My goal is to populate a dropdown list with the values from the workgroup field so users can select a value and retrieve all records associated with it.
Although I am able to retrieve the values using Ruby (verified through the console), I am facing challenges when trying to populate the dropdown list. Here is my current Ruby statement:
get '/workgroup' do
Record.all.to_a.collect(&:workgroup).uniq.to_json
end
The JavaScript code snippet I attempted to use is as follows:
<script>
//var json = 'http://localhost:4567/api/v1/workgroup';
$(document).ready(function()
{
$.getJSON("/api/v1/workgroup",function(obj)
{
$.each(json.records,function(key,value)
{
var option = $('<option />').val(value.workgroup);
$("#dropDownDest").append(option);
})
})
});
</script>
Once the dropdown is populated, my plan is to utilize the selected value to fetch and display all records with that specific workgroup in a table. I have yet to figure out that part, but I am taking it one step at a time!
Thank you for your assistance!