0

Most likely similar questions have been asked, but weirdly I can't find it using those keywords...

Let's say you have a model Actor with a field :name. Now somewhere else there is a model Movie which has_many :actors. I'm trying to make a form where I can dynamically add some actors to a movie.

Using angularJS I would have used typeahead:

<input type="text" ng-model="actor_selected" placeholder="Add actor to movie" 
 typeahead="actor as actor.name for actor in actors">

Which basically shows and autocompletes by actor name, but internally saves the actor_id in $scope.actor_selected

How can i do that using rails-autocomplete plugin in an .erb file? The following isn't working/doing what I want :

<%= f.autocomplete_field :actor_id, movies_autocomplete_actor_name_path, class: "form-control" %>
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164

1 Answers1

0

Fast answer: using :id-element provided by the gem autocomplete.

Long answer : Even with this, I couldn't find a way to do exactly what I wanted so I hed to reimplement the backend part.

I have described everything in the answer I gave in this question.

Community
  • 1
  • 1
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164