I have Post table with title and content attributes. I want to make auto complete textfield where user are suggested by Post title. I am trying to add jquery auto-complete in my rails application. I am doing like this ..
controller (Adding Posts title in Array)--
@posttitle = []
Post.all.each do |g|
@posttitle << g.title
end
View --
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<%= text_field_tag :search, params[:search], :placeholder => "Search Religious Places...", :id=>"tags" %>
<script>
$(function() {
var availableTags = <%= @posttitle %>;
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
But its not showing any suggestion (auto-complete is not working). I don't know whats going wrong. Please help
Have you tried something like this:
<script>
var availableTags = <%= raw @posttitle %>;
$(function() {
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With