Fergus Morton Fergus Morton - 9 months ago 23
Ruby Question

Display name from array in auto-complete search bar

I am trying to auto-complete a search bar from a table

with the string

Here is the JavaScript I have in

$(function() {
var availableTags = "<%= @remedies_remedyName%>";

$( "#autoComplete" ).autocomplete({
source: availableTags

Here is the code in
Pages Controller

def home
@remedies = Remedy.all

Here is the html in

<div class="carousel-caption searchbar">
<form class="search" action="/pages/searchremedy" method="get">
<input id="autoComplete" class="searchTerm" name="searchremedy" placeholder=" Search by treatment type, or tell us what you'd like to treat..." />
<input class="searchButton" type="submit" placeholder="Search" />


You are printing out Ruby variable @remedies_remedyName into your javascript. It does not look like you have defined this instance variable.

var availableTags = "<%= @remedies_remedyName%>";

Update your js code to the following:

var availableTags = "<%= raw(@remedies.map(&:remedyName)).html_safe %>";

Note: I am assuming you have column named remedyName in your Remedy table.