Reputation: 61
Just wondering how I might filter the results of a controller when finding nearby 'clients' in my case
I have this on my show page
<% for client in @due.nearbys(15) %>
<tr><td><b><%= link_to client.name, client %> <%= link_to client.surname, client %>:</b>
<%= link_to client.scheduled_date.strftime('%A %m-%d-%y'), client %>
On my clients_controller I specified
@due = current_user.clients.where(['scheduled_date < ?', 6.months.ago]).order('scheduled_date DESC')
However I get
undefined method `nearbys' for #<Client::ActiveRecord_AssociationRelation:0x00007fb2a2aea67>
not sure how to call the clients nearbys whcih does work normally but to add the filter, should I add it as a scope? thanks!
Upvotes: 0
Views: 142
Reputation: 411
It's depending on your logic. but for get nearbys
Client.near([this_client.lng, this_client.lat], 50, units: :km).where('actived_at', '<=', 3.months.ago)
Something like above code. the where conditions is depend on your business.
Upvotes: 1