vendredi 6 novembre 2015

rails geocoder gem find users that have matching address

I'm using the geocoder gem for my rails app that pulls in the longitude and latitude for each users address. Each profile of the user has an address (and more later). The profile currently has_one address and the address belongs_to the profile.

What I want to do is search the area so I am using the near() function which works fine on the controller when I want to search the Address model. It returns to me an @ instance which I can use in the view and I loop through the results pulling the address.profile.suburb or .name etc form each address result. But this is done in the view.

What I would like to do is have an instance of @users since the next thing I want to do is filter by other models - I have a Style model that if they have checked the filter Style - any user with Style AND has an address near() will return into a @user instance and then I can use that in the view.

Not sure how to do this and everything I try doesn't work - I thought it would be something like User.all.profiles.address.near(params[:search])

but then I need to also filter by style which is in a table not connected to address (it's to the user model)

or something like that...

help appreciated.

Aucun commentaire:

Enregistrer un commentaire