这是一个使人们可以选择要与当前文章关联的文章的字段:
<%= form_for(Relation.create, remote: true) do |f| %>
<%= f.hidden_field :dependent_id, :value => @article.id %>
<%= f.collection_select :dependency_id, Article.all.reject{|x| (x.dependency_hack.map{|x| x.dependent_id}.include? @article.id) &&
(if current_user then x.dependency_hack.map{|x| x.user}.include? current_user end) ||
x.id == @article.id}, :id, :title, {} %>
<%= f.submit "Add suggestion" %>
<% end %>
但这会加载所有文章标题,这既浪费又缓慢。而是应该在用户键入几个字符后动态加载标题。