最有可能提出类似的问题,但奇怪的是我无法使用这些关键字找到它...
假设你有一个带有字段的模型Actor :name 。 现在在其他地方有一个模特Movie ,其中有很多人has_many :actors 。 我正在尝试创建一个表单,我可以动态地将一些演员添加到电影中。
使用angularJS我会使用typeahead:
<input type="text" ng-model="actor_selected" placeholder="Add actor to movie" typeahead="actor as actor.name for actor in actors">它基本上按actor名称显示和自动填充,但在内部将actor_id保存在$scope.actor_selected
如何在.erb文件中使用rails-autocomplete插件? 以下不能正常工作/做我想做的事:
<%= f.autocomplete_field :actor_id, movies_autocomplete_actor_name_path, class: "form-control" %>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" %>最满意答案
快速回答:使用:由gem autocomplete提供的id-element。
答案很长:即便如此,我找不到一种方法可以完全按照自己的意愿行事,所以我会重新实现后端部分。
我在这个问题的答案中描述了一切。
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.
更多推荐
发布评论