Tuesday, August 31, 2010

NoMethodError: undefined method 'coordinates' for #


In trying to use the latest Sunspot code (from github) for geo search with Rails 3.0.0 , I was getting the following error while running Sunspot.index!(Location.all), where Location is my ActiveRecord class for storing locations:

After searching through the new code I found that coordinates is no longer a valid field type, but instead location is to be used. location expects an object that responds to lat and lng. Sunspot provides a handly little struct called Coordinates to be this object. So, here is my model code for setting up the search:

notice the virtual attribute called coordinates which wraps the lat & lng ActiveRecord attributes. My search code now looks like this:

And my search results are coming in as expected.

No comments:

Post a Comment