Ruby on Rails - Railscasts PRO #399 Autocomplete Search Terms (pro)
Why Stack Overflow recommends it
Stack Overflow users link it when answering Rails questions about autocomplete, live search, and jQuery UI autocomplete wired to a database.
Recommended by 5 people across 5 different months, 2015 to 2017.
What it is
A Railscasts PRO episode (reuploaded by Railscasts Reloaded) showing how to add autocompletion to a Rails search form. It then speeds the feature up with Rack middleware, caching, and a move from SQL queries to Redis.
What people said
Recommends mrtorks · 2015-08 · Stack Overflow · on “Following Railscast #102 on Rails 4 - Autocomplete_source won't work, but local list does”
I see your pain since I recently started learning rails. The problem is not in rails 4, but actually your source. This line of code does not work properly: source: $('#post_category_name').autocomplete The link below goes deeper into autocomplete and even helps you speed up the query using redis which is pretty fast. Ryan also includes rake tasks to help reindex the tables in your database Autocomplete Pro [this video] I suggest you spend time looking at this video. It would help a lot.
Recommends Bryan Dimas · 2015-10 · Stack Overflow · on “changing collection select to autocomplete association in rails 4 for create action”
I'll just put it out there, that railscast is for Rails 3. You're probably using Rails 4 and you should. So here's a railscast tutorial for autocomplete in Rails 4: [this video]
Recommends Richard Peck · 2015-11 · Stack Overflow · on “Rails collection select when collection is way big”
You'll be better using something called AutoComplete / LiveSearch [this video] with a text box (like Pardeep Saini mentioned). We've done this before: [LINK] You could achieve this relatively simply: = f.text_field :user_ids, placeholder: "Search for users" You'd then have to use javascript : #app/assets/javascripts/application.js $(document).on("keyup", "input[type=text]#user_ids", function(){ $.getJSON("users/search", {name: $(this).val()}).done(function(json){ var users = []; $.each(json.users, function(user) { users.push("<a href=\"#\" id="+ user.id +">" + user.name + "</a>"); }); $(".search").html(users).show(); }); }); $(document).on("click", ".search a", function(e) { e.preventDefault(); /
Recommends user5715347 · 2016-05 · Stack Overflow · on “search function for conversations in ruby on rails”
In the model of conversations or whatever you have named it put something like this search method: def self.search(search) if search where(['title LIKE ? or content LIKE ?', "%#{search}%","%#{search}%"]) end end Then in the index have something like this: <%= form_tag conversations_path, :method => 'get' do %> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", name: nil %> <% end %> Finally in the controller have something like this: @conversation= Conversation.search(params[:search]) See this videos to better understand searching in rails: [LINK] [LINK] [LINK] [this video] [LINK] [LINK] [LINK] [LINK] Note the first one is what i think suits you best. It is a simple search an
Recommends Charles Magnussen · 2016-06 · Stack Overflow · on “Autocomplete jquery and Rails4”
I think you can use Jquery UI, because this kind of functionality is bettre with js. This video has around 1 year hope works for you. Tutorial [this video] Sometimes use a gem is not the best solution. Regards
Cites koz · 2016-09 · Stack Overflow · on “Ruby on Rails: Cant figure out why my jQuery-ui autocomplete isn't working?”
I just followed a youtube tutorial on adding a jQuery-ui autocomplete feature to my search field. This is the link to the tutorial: [this video] . For some reason it is not working, despite going over the tutorial and rechecking syntax constantly. I'm NOT getting any errors when I reload the web browser, however, nothing appears as a drop down menu as I type in the search field. Interestingly though, if I use an array for sample data, it works (the drop down menu appears with suggestions using the sample array data). But when I try to link it to my database of posts, it no longer works. I have shown example code for both ways below. My code is below - any help is much appreciated i've been trying
Cites advice · 2017-01 · Stack Overflow · on “Ruby on Rails - Pass value from Javascript to Model”
I'm trying to implement an autocomplete field into my _form.html.erb to allow the user to enter Categories and save the object. I was following this Railscast video [this video] for setting up the autocomplete, but it was for searching. // application.js $( "#tags" ).autocomplete({ source: "/search_suggestions" }); $('#tags').on('autocompleteselect', function (e, ui) { $('#tagsname').html('You selected: ' + ui.item.value); }); With this, I can populate the recommendations with the correct values, and get a callback when a user selects a value. // _form.html.erb <div id="tagsname"></div> <%= bootstrap_form_for(group) do |f| %> <%= f.text_field :title %> <%= f.text_area :description %> <%= f.static