Implementing auto complete for more than one field in Rails

前端 未结 1 1053
难免孤独
难免孤独 2021-01-28 20:24

I have an app, which implements a group feature. Each group has n members. Also, each group has a group specific profile pic to it.

I have been able to implement auto c

1条回答
  •  不知归路
    2021-01-28 20:30

    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:

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

    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.

    0 讨论(0)
提交回复
热议问题