1

Can anyone tell me how to easily implement auto-complete in rails 3.1?thanks. p.s. What's the best solution for simple_form to do this??

Besides, I also want to know how to implement meetup's RSVP instant push in rails?

I have the following form, but it didn't work, please advise.

%table
= simple_form_for(@book) do |f|
%th book name
%th
= f.input :name, label: false, placeholder: "add a name", :wrapper_html => { :id => 'autocomplete' }
= f.input :object, autofocus: true, label: false
%th
= f.button :submit, "Yes!"
Jason Wong
  • 21
  • 4

1 Answers1

1

I built a simple Rails 3.1 app using the jQueryUI autocompletion feature here. You simply add the jQueryUI library to your assets, add a css class or id to the actual text field that shall be autocompleted and put some javascript logic in your application, like:

$(function() {
  $('#autocomplete').autocomplete({
    source: '/movies/autocomplete'
  });
});

with #autocomplete the css id of the text field. '/movies/autocomplete' is the actual route that will HTTp requested with the data that's put into the text field. In the movies#autocomplete action you then use that param to search for data for the autocompletion. Depending in what kind of jQueryUI autocompletion you use, you simply return an array like [{:label => 'FOO', :value => 'foo'}, ...] as JSON. label is the text you get autocompleted, value is the text that is put into the text field when clicking the label. I think and hope the code from the repo is quite understandable. Also, have a look at the JQueryUI library.

Though there shouldn't be a problem with simple_form, since it's just the text field that gets touched.

Best regards

Tobias

tbuehlmann
  • 9,032
  • 5
  • 27
  • 33