I am trying to use an autocomplete function for when the user attempts to enter in an license plate number into the appropriate rails form. I've been going through easyautocomplete and jquery-ui autocomplete. However can't seem to get any of them to work because the license_number attribute is a nested attribute and I can't find a way to get it all associated.
permit.rb
class Permit < ApplicationRecord
self.primary_key = :permit_id
has_one :vehicle
accepts_nested_attributes_for :vehicle
vehicle.rb
class Vehicle < ApplicationRecord
self.primary_key = :vehicle_id
belongs_to :permit, optional: true
permit form
<%= form_with(model: permit, local: true) do |form| %>
...
<div class="field">
<%= form.fields_for :vehicle do |f| %>
<%= f.label :license_number %>
<%= f.text_field :license_number %>
<% end %>
</div>
...
The vehicle model has a attribute called license_number. How do I grab all of the license numbers from that model and get it associated so I can use an autocomplete function?
edit
permits.coffee
jQuery ->
$('#vehicle_license_number').autocomplete
source: vehicle.collect( |car| [car.license_number, car.vehicle_id])
source
as a function, where you can custom search for nested element versus top element. Also include an example of the data.