First, the example I read in the docs shows to declare the associated model as singular, :address, but if I do I get the error Association named 'address' was not found on User; If I change it to plural :addresses, then the next problem I have is the association doesn't work in views undefined method `country' for ... Why am I declaring the association as plural and how can I make the association available in the view
User.rb:
class User < ActiveRecord::Base
searchkick word_middle: ['full_name', 'description', 'interests']
has_many :addresses
scope :search_import, -> { includes(:addresses) }
search.html.erb:
<% @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=?", 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>