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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -