Implementing auto complete for more than one field in Rails

二次信任 提交于 2019-12-02 07:58:47
Otavio

So, in parts:

  1. When you get the investor groups, you're getting only the titles with the call "collect(&:title)". Remove it to get the whole object;
  2. You don't need use the regex, you already get the titles that match with the LIKE in conditions;
  3. Instead of render inline, try to make a partial that render all that you need inside the LI tag. Render inline and content_tag are good when all that you need is a small text, but with "bigger things", prefer partials.

Sorry any engrish.

Update:

The collect(&:title) says "from all investor_groups that you find, give me only their titles". So, remove it completely, using only:

InvestorGroup.find(:all, find_options)

It says "give me the investor_groups that you find", so you will have an array of investor_groups to use in the partial. With this, you can show the data that you want in the autocomplete list, like you did in the index.html, with a "for" statement, putting inside the "li" elements the images, the title and the activated members size.

Sorry any engrish.

Re-Update

Almost there. To the autocomplete works, the response from the autocomplete method must be a list. So, the partial would be like:

<ul>
  <% for inv_group in @investor_group2 %>
    <li><%=h inv_group.title %>, <%=h inv_group.activated_members.size %></li>
  <%end%>
</ul>

Each item wrapped by a li tag, and all wrapped by an ul tag. If you look the previous code, this is exactly how it works:

content_tag(:ul, @investor_group2.map { |title| content_tag(:li, h(title)) })

An ul content tag, wrapping li content tags that wrap the titles.

And I did separate the title and the size in two erb, because I never tried put two information in the same, and don't now if it works.

Sorry any engrish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!