Skip to content

Instantly share code, notes, and snippets.

@scy
Created September 11, 2011 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scy/1209598 to your computer and use it in GitHub Desktop.
Save scy/1209598 to your computer and use it in GitHub Desktop.
Initializing a jQuery UI autocomplete with data from a Rails array
<script type="text/javascript">
// Trying to help @gedankenstuecke here. A bit hard because I don’t speak Rails (neither Ruby) and can’t try live what the output looks like.
$(function () {
$("#<%=p.object.phenotype_id.to_json%>").autocomplete({
source: <%=Phenotype.find_by_id(p.object.phenotype_id).known_phenotypes.to_json%>
});
});
</script>
@scy
Copy link
Author

scy commented Sep 11, 2011

Okay, this will still escape the source JSON string according to HTML rules, leading to &quot; in the JavaScript, which is wrong. But I don’t know how to fix that, I’m not a Rails guy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment