Ruby on Rails - Railscasts PRO #102 Auto-Complete Association (revised)

Railscasts Reloaded · 17K views · 2014 · 9:06

Open on YouTube

Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the reference walkthrough when asking how to wire up jQuery UI autocomplete for a Rails association field, and often get stuck adapting it to newer Rails versions.

Recommended by 1 people across 1 different months, 2015 to 2018.

What it is

A short Railscasts PRO screencast showing how to set a belongs_to association with a text field and autocomplete instead of a select menu. It builds two versions with jQuery UI, one that filters on the client side and one that queries the server.

What people said

Recommends x6iae · 2015-12 · Stack Overflow · on “Rails: Autocomplete / Search”

You can use the jquery-ui-rails gem [LINK] , according to this rails-cast episode [LINK] . It will work well for you. You can also find it here. [this video]

Cites AarCee · 2015-07 · Stack Overflow · on “Jquery ui autocomplete not working with rails 4.2”

I'm working on a Rails 4.2 app (with Bootstrap) and trying to set up autocomplete in a text field. I'm following the Railscasts autocomplete association episode [this video] : My application.js looks like: //= require jquery //= require jquery-ui //= require jquery_ujs //= require turbolinks and my application.css contains: * *= require_tree . *= require_self *= require jquery-ui */ The model "modelname" contains a text field "email". In the view file new.html.erb for modelname I have: <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= form_for(@modelname) do |f| %> <%= f.label "EmailId" %> <%= f.text_field :email %> <%= f.submit "Create", class: "btn btn-primary" %> <% end %> </div> </

Cites Mathias · 2015-10 · Stack Overflow · on “Rails autocomplete textfield won't work”

Followed this guide by railscasts to setup autocompletion on collection_select. [this video] In my example I'm trying to create a chatroom with a game related. MODEL belongs_to :game validates :game, presence: true def game_name game.try(:name) end def game_name=(name) self.game = Game.where(name: name).first_or_create if name.present? end CONTROLLER def create @room = current_user.chatrooms.build(room_params) if @room.save redirect_to @room else render 'new' end end def room_params params.require(:chatroom).permit(:title, :description, :game_id) end HTML <%= simple_form_for @room do |f| %> <p class="ftitle">Chatroom title</p> <%= f.input :title, label: false %> <p class="ftitle">Chatroom descrip

Cites Sean Magyar · 2015-10 · Stack Overflow · on “changing collection select to autocomplete association in rails 4 for create action”

Hey Bryan, [this video] Yeah autocompletion was not there yet since I couldn't create the task. Now task creation is working w/ the code above, but I don't see how I could put there the autcomplete function for my task_name_company method.

Cites Alaa Othman · 2016-08 · Stack Overflow · on “Dynamic forms - Auto fill fields based on previous auto complete”

I have a form with two fields phone and name what i want is when the user selects a phone number using ajax autocomplete the name field will be auto filled with the name that correspond to that phone number. Watching that Railscasts episode [this video] i was able to make ajax autocomplete works, any clean way of doing the auto filling? patients_controller class PatientsController < ApplicationController def index @patients = Patient.order(:phone).where('phone like ?', "%#{params[:term]}%") json_data = @patients.map(&:phone) render json: json_data end end reservations.coffee $(document).ready -> $('#patient_phone').autocomplete source: "/patients/index" _form.erb <%= f.fields_for :patient, appoin

Cites Alexander Gorg · 2018-06 · Stack Overflow · on “How to add autocomplete from jquery-ui to Rails 5 project?”

I'm trying to implement jquery-ui's autocomplete, but seems like I'm missing something very important. I'm following these guide from Railscasts [LINK] (also available on [this video] ). But I'm using Rails 5.1 and respectively yarn instead of the gem. Also I'd like to mention that I already have datepicker and tabs implemented and working well. Here is package.json 's dependencies: "dependencies": { "jquery": "^3.3.1", "jquery-ui": "^1.12.1", "rails-ujs": "^5.2.0", "turbolinks": "^5.1.1" }, So in the top of my application.js I have this: //= require jquery //= require jquery-ui/ui/widget //= require jquery-ui/ui/widgets/datepicker //= require jquery-ui/ui/widgets/autocomplete //= require jquery-