user3828016
user3828016

Reputation:

Autocomplete in Ruby on rails 4

In my application I have a drop-down, I want to input a value in a text-field and while inputting it the drop-down should display the option for auto-completing it. Following is the code snippet

<div class="field">
  <%= f.label :patient_id %><br>
  <%= f.collection_select(:patient_id, Patient.all, :id, :patient_identity, {:prompt => "Select patient"}, :selected => @vital.patient_id, required: true) %>
</div>

In the above code I have the drop-down that display all the option. What changes or what tag should I have to use input-text field and it's auto-complete feature.

Upvotes: 0

Views: 52

Answers (2)

user3828016
user3828016

Reputation:

Answering to my own question. I have solved this problem with gem called 'chosen-rails' : https://github.com/tsechingho/chosen-rails. Simply awesome.

Upvotes: 0

Brittany Hicks
Brittany Hicks

Reputation: 34

You can use jquery-ui autocomplete. And then just set up your controller to return a json response with the data you want. Check out this blog post. Hope it helps.

Upvotes: 1

Related Questions