javascript - Display name from array in auto-complete search bar -
i trying auto-complete search bar table remedy
string remedyname
.
here javascript have in \pages\home.html.erb
$(function() { var availabletags = "<%= @remedies_remedyname%>"; $( "#autocomplete" ).autocomplete({ source: availabletags }); });
here code in pages controller
def home @remedies = remedy.all end
here html in /pages/home
<div class="carousel-caption searchbar"> <form class="search" action="/pages/searchremedy" method="get"> <input id="autocomplete" class="searchterm" name="searchremedy" placeholder=" search treatment type, or tell you'd treat..." /> <input class="searchbutton" type="submit" placeholder="search" /> </form> </div>
you printing out ruby variable @remedies_remedyname
javascript. not have defined instance variable.
var availabletags = "<%= @remedies_remedyname%>";
update js code following:
var availabletags = "<%= raw(@remedies.map(&:remedyname)).html_safe %>";
note: assuming have column named remedyname
in remedy
table.
Comments
Post a Comment