Ruby on Rails Wednesday, February 5, 2020

How do I show associations in a view with searchkick? I get error association not found even though user has_many_addresses
My user model has

scope :search_import, -> { includes(:addresses) }

search.html.erb:

<h3><%= (t 'search_results_for') %> <%= @terms %></h3>
<ul>
 <% @users.each do |u| %>
  <li>
      <%= link_to "#{u.first_name} #{u.middle_name} #{u.last_name}", page_path(name: u.name) %>
    <% ua=u.addresses.where("current=?, limit: 1", true)  %>
        <% if ua.country=="US" %>
            <%= ua.city %>, <%= ua.state %> <%= ISO3166::Country.find_country_by_alpha2(ua.country) %>
        <% else %>
            <%= ua.city %>, <%= ISO3166::Country.find_country_by_alpha2(ua.country) %>
        <% end %>
  </li>
 <% end %>
</ul>


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/34df3737-250d-4dfa-b9ed-3ffb06c7354b%40googlegroups.com.

No comments:

Post a Comment